id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
13,400
OpenTSDB/opentsdb
src/utils/Config.java
Config.overrideConfig
public void overrideConfig(final String property, final String value) { properties.put(property, value); loadStaticVariables(); }
java
public void overrideConfig(final String property, final String value) { properties.put(property, value); loadStaticVariables(); }
[ "public", "void", "overrideConfig", "(", "final", "String", "property", ",", "final", "String", "value", ")", "{", "properties", ".", "put", "(", "property", ",", "value", ")", ";", "loadStaticVariables", "(", ")", ";", "}" ]
Allows for modifying properties after creation or loading. WARNING: This should only be used on initialization and is meant for command line overrides. Also note that it will reset all static config variables when called. @param property The name of the property to override @param value The value to store
[ "Allows", "for", "modifying", "properties", "after", "creation", "or", "loading", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L317-L320
13,401
OpenTSDB/opentsdb
src/utils/Config.java
Config.getBoolean
public final boolean getBoolean(final String property) { final String val = properties.get(property).trim().toUpperCase(); if (val.equals("1")) return true; if (val.equals("TRUE")) return true; if (val.equals("YES")) return true; return false; }
java
public final boolean getBoolean(final String property) { final String val = properties.get(property).trim().toUpperCase(); if (val.equals("1")) return true; if (val.equals("TRUE")) return true; if (val.equals("YES")) return true; return false; }
[ "public", "final", "boolean", "getBoolean", "(", "final", "String", "property", ")", "{", "final", "String", "val", "=", "properties", ".", "get", "(", "property", ")", ".", "trim", "(", ")", ".", "toUpperCase", "(", ")", ";", "if", "(", "val", ".", "equals", "(", "\"1\"", ")", ")", "return", "true", ";", "if", "(", "val", ".", "equals", "(", "\"TRUE\"", ")", ")", "return", "true", ";", "if", "(", "val", ".", "equals", "(", "\"YES\"", ")", ")", "return", "true", ";", "return", "false", ";", "}" ]
Returns the given property as a boolean Property values are case insensitive and the following values will result in a True return value: - 1 - True - Yes Any other values, including an empty string, will result in a False @param property The property to load @return A parsed boolean @throws NullPointerException if the property was not found
[ "Returns", "the", "given", "property", "as", "a", "boolean" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L412-L421
13,402
OpenTSDB/opentsdb
src/utils/Config.java
Config.getDirectoryName
public final String getDirectoryName(final String property) { String directory = properties.get(property); if (directory == null || directory.isEmpty()){ return null; } if (IS_WINDOWS) { // Windows swings both ways. If a forward slash was already used, we'll // add one at the end if missing. Otherwise use the windows default of \ if (directory.charAt(directory.length() - 1) == '\\' || directory.charAt(directory.length() - 1) == '/') { return directory; } if (directory.contains("/")) { return directory + "/"; } return directory + "\\"; } if (directory.contains("\\")) { throw new IllegalArgumentException( "Unix path names cannot contain a back slash"); } if (directory == null || directory.isEmpty()){ return null; } if (directory.charAt(directory.length() - 1) == '/') { return directory; } return directory + "/"; }
java
public final String getDirectoryName(final String property) { String directory = properties.get(property); if (directory == null || directory.isEmpty()){ return null; } if (IS_WINDOWS) { // Windows swings both ways. If a forward slash was already used, we'll // add one at the end if missing. Otherwise use the windows default of \ if (directory.charAt(directory.length() - 1) == '\\' || directory.charAt(directory.length() - 1) == '/') { return directory; } if (directory.contains("/")) { return directory + "/"; } return directory + "\\"; } if (directory.contains("\\")) { throw new IllegalArgumentException( "Unix path names cannot contain a back slash"); } if (directory == null || directory.isEmpty()){ return null; } if (directory.charAt(directory.length() - 1) == '/') { return directory; } return directory + "/"; }
[ "public", "final", "String", "getDirectoryName", "(", "final", "String", "property", ")", "{", "String", "directory", "=", "properties", ".", "get", "(", "property", ")", ";", "if", "(", "directory", "==", "null", "||", "directory", ".", "isEmpty", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "IS_WINDOWS", ")", "{", "// Windows swings both ways. If a forward slash was already used, we'll", "// add one at the end if missing. Otherwise use the windows default of \\", "if", "(", "directory", ".", "charAt", "(", "directory", ".", "length", "(", ")", "-", "1", ")", "==", "'", "'", "||", "directory", ".", "charAt", "(", "directory", ".", "length", "(", ")", "-", "1", ")", "==", "'", "'", ")", "{", "return", "directory", ";", "}", "if", "(", "directory", ".", "contains", "(", "\"/\"", ")", ")", "{", "return", "directory", "+", "\"/\"", ";", "}", "return", "directory", "+", "\"\\\\\"", ";", "}", "if", "(", "directory", ".", "contains", "(", "\"\\\\\"", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unix path names cannot contain a back slash\"", ")", ";", "}", "if", "(", "directory", "==", "null", "||", "directory", ".", "isEmpty", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "directory", ".", "charAt", "(", "directory", ".", "length", "(", ")", "-", "1", ")", "==", "'", "'", ")", "{", "return", "directory", ";", "}", "return", "directory", "+", "\"/\"", ";", "}" ]
Returns the directory name, making sure the end is an OS dependent slash @param property The property to load @return The property value with a forward or back slash appended or null if the property wasn't found or the directory was empty.
[ "Returns", "the", "directory", "name", "making", "sure", "the", "end", "is", "an", "OS", "dependent", "slash" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L429-L459
13,403
OpenTSDB/opentsdb
src/utils/Config.java
Config.hasProperty
public final boolean hasProperty(final String property) { final String val = properties.get(property); if (val == null) return false; if (val.isEmpty()) return false; return true; }
java
public final boolean hasProperty(final String property) { final String val = properties.get(property); if (val == null) return false; if (val.isEmpty()) return false; return true; }
[ "public", "final", "boolean", "hasProperty", "(", "final", "String", "property", ")", "{", "final", "String", "val", "=", "properties", ".", "get", "(", "property", ")", ";", "if", "(", "val", "==", "null", ")", "return", "false", ";", "if", "(", "val", ".", "isEmpty", "(", ")", ")", "return", "false", ";", "return", "true", ";", "}" ]
Determines if the given propery is in the map @param property The property to search for @return True if the property exists and has a value, not an empty string
[ "Determines", "if", "the", "given", "propery", "is", "in", "the", "map" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L466-L473
13,404
OpenTSDB/opentsdb
src/utils/Config.java
Config.dumpConfiguration
public final String dumpConfiguration() { if (properties.isEmpty()) return "No configuration settings stored"; StringBuilder response = new StringBuilder("TSD Configuration:\n"); response.append("File [" + config_location + "]\n"); int line = 0; for (Map.Entry<String, String> entry : properties.entrySet()) { if (line > 0) { response.append("\n"); } response.append("Key [" + entry.getKey() + "] Value ["); if (entry.getKey().toUpperCase().contains("PASS")) { response.append("********"); } else { response.append(entry.getValue()); } response.append("]"); line++; } return response.toString(); }
java
public final String dumpConfiguration() { if (properties.isEmpty()) return "No configuration settings stored"; StringBuilder response = new StringBuilder("TSD Configuration:\n"); response.append("File [" + config_location + "]\n"); int line = 0; for (Map.Entry<String, String> entry : properties.entrySet()) { if (line > 0) { response.append("\n"); } response.append("Key [" + entry.getKey() + "] Value ["); if (entry.getKey().toUpperCase().contains("PASS")) { response.append("********"); } else { response.append(entry.getValue()); } response.append("]"); line++; } return response.toString(); }
[ "public", "final", "String", "dumpConfiguration", "(", ")", "{", "if", "(", "properties", ".", "isEmpty", "(", ")", ")", "return", "\"No configuration settings stored\"", ";", "StringBuilder", "response", "=", "new", "StringBuilder", "(", "\"TSD Configuration:\\n\"", ")", ";", "response", ".", "append", "(", "\"File [\"", "+", "config_location", "+", "\"]\\n\"", ")", ";", "int", "line", "=", "0", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "String", ">", "entry", ":", "properties", ".", "entrySet", "(", ")", ")", "{", "if", "(", "line", ">", "0", ")", "{", "response", ".", "append", "(", "\"\\n\"", ")", ";", "}", "response", ".", "append", "(", "\"Key [\"", "+", "entry", ".", "getKey", "(", ")", "+", "\"] Value [\"", ")", ";", "if", "(", "entry", ".", "getKey", "(", ")", ".", "toUpperCase", "(", ")", ".", "contains", "(", "\"PASS\"", ")", ")", "{", "response", ".", "append", "(", "\"********\"", ")", ";", "}", "else", "{", "response", ".", "append", "(", "entry", ".", "getValue", "(", ")", ")", ";", "}", "response", ".", "append", "(", "\"]\"", ")", ";", "line", "++", ";", "}", "return", "response", ".", "toString", "(", ")", ";", "}" ]
Returns a simple string with the configured properties for debugging @return A string with information about the config
[ "Returns", "a", "simple", "string", "with", "the", "configured", "properties", "for", "debugging" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L479-L500
13,405
OpenTSDB/opentsdb
src/utils/Config.java
Config.loadConfig
protected void loadConfig() throws IOException { if (config_location != null && !config_location.isEmpty()) { loadConfig(config_location); return; } final ArrayList<String> file_locations = new ArrayList<String>(); // search locally first file_locations.add("opentsdb.conf"); // add default locations based on OS if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) { file_locations.add("C:\\Program Files\\opentsdb\\opentsdb.conf"); file_locations.add("C:\\Program Files (x86)\\opentsdb\\opentsdb.conf"); } else { file_locations.add("/etc/opentsdb.conf"); file_locations.add("/etc/opentsdb/opentsdb.conf"); file_locations.add("/opt/opentsdb/opentsdb.conf"); } for (String file : file_locations) { try { FileInputStream file_stream = new FileInputStream(file); Properties props = new Properties(); props.load(file_stream); // load the hash map loadHashMap(props); } catch (Exception e) { // don't do anything, the file may be missing and that's fine LOG.debug("Unable to find or load " + file, e); continue; } // no exceptions thrown, so save the valid path and exit LOG.info("Successfully loaded configuration file: " + file); config_location = file; return; } LOG.info("No configuration found, will use defaults"); }
java
protected void loadConfig() throws IOException { if (config_location != null && !config_location.isEmpty()) { loadConfig(config_location); return; } final ArrayList<String> file_locations = new ArrayList<String>(); // search locally first file_locations.add("opentsdb.conf"); // add default locations based on OS if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) { file_locations.add("C:\\Program Files\\opentsdb\\opentsdb.conf"); file_locations.add("C:\\Program Files (x86)\\opentsdb\\opentsdb.conf"); } else { file_locations.add("/etc/opentsdb.conf"); file_locations.add("/etc/opentsdb/opentsdb.conf"); file_locations.add("/opt/opentsdb/opentsdb.conf"); } for (String file : file_locations) { try { FileInputStream file_stream = new FileInputStream(file); Properties props = new Properties(); props.load(file_stream); // load the hash map loadHashMap(props); } catch (Exception e) { // don't do anything, the file may be missing and that's fine LOG.debug("Unable to find or load " + file, e); continue; } // no exceptions thrown, so save the valid path and exit LOG.info("Successfully loaded configuration file: " + file); config_location = file; return; } LOG.info("No configuration found, will use defaults"); }
[ "protected", "void", "loadConfig", "(", ")", "throws", "IOException", "{", "if", "(", "config_location", "!=", "null", "&&", "!", "config_location", ".", "isEmpty", "(", ")", ")", "{", "loadConfig", "(", "config_location", ")", ";", "return", ";", "}", "final", "ArrayList", "<", "String", ">", "file_locations", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "// search locally first", "file_locations", ".", "add", "(", "\"opentsdb.conf\"", ")", ";", "// add default locations based on OS", "if", "(", "System", ".", "getProperty", "(", "\"os.name\"", ")", ".", "toUpperCase", "(", ")", ".", "contains", "(", "\"WINDOWS\"", ")", ")", "{", "file_locations", ".", "add", "(", "\"C:\\\\Program Files\\\\opentsdb\\\\opentsdb.conf\"", ")", ";", "file_locations", ".", "add", "(", "\"C:\\\\Program Files (x86)\\\\opentsdb\\\\opentsdb.conf\"", ")", ";", "}", "else", "{", "file_locations", ".", "add", "(", "\"/etc/opentsdb.conf\"", ")", ";", "file_locations", ".", "add", "(", "\"/etc/opentsdb/opentsdb.conf\"", ")", ";", "file_locations", ".", "add", "(", "\"/opt/opentsdb/opentsdb.conf\"", ")", ";", "}", "for", "(", "String", "file", ":", "file_locations", ")", "{", "try", "{", "FileInputStream", "file_stream", "=", "new", "FileInputStream", "(", "file", ")", ";", "Properties", "props", "=", "new", "Properties", "(", ")", ";", "props", ".", "load", "(", "file_stream", ")", ";", "// load the hash map", "loadHashMap", "(", "props", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "// don't do anything, the file may be missing and that's fine", "LOG", ".", "debug", "(", "\"Unable to find or load \"", "+", "file", ",", "e", ")", ";", "continue", ";", "}", "// no exceptions thrown, so save the valid path and exit", "LOG", ".", "info", "(", "\"Successfully loaded configuration file: \"", "+", "file", ")", ";", "config_location", "=", "file", ";", "return", ";", "}", "LOG", ".", "info", "(", "\"No configuration found, will use defaults\"", ")", ";", "}" ]
Searches a list of locations for a valid opentsdb.conf file The config file must be a standard JAVA properties formatted file. If none of the locations have a config file, then the defaults or command line arguments will be used for the configuration Defaults for Linux based systems are: ./opentsdb.conf /etc/opentsdb.conf /etc/opentsdb/opentdsb.conf /opt/opentsdb/opentsdb.conf @throws IOException Thrown if there was an issue reading a file
[ "Searches", "a", "list", "of", "locations", "for", "a", "valid", "opentsdb", ".", "conf", "file" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L645-L687
13,406
OpenTSDB/opentsdb
src/utils/Config.java
Config.loadConfig
protected void loadConfig(final String file) throws FileNotFoundException, IOException { final FileInputStream file_stream = new FileInputStream(file); try { final Properties props = new Properties(); props.load(file_stream); // load the hash map loadHashMap(props); // no exceptions thrown, so save the valid path and exit LOG.info("Successfully loaded configuration file: " + file); config_location = file; } finally { file_stream.close(); } }
java
protected void loadConfig(final String file) throws FileNotFoundException, IOException { final FileInputStream file_stream = new FileInputStream(file); try { final Properties props = new Properties(); props.load(file_stream); // load the hash map loadHashMap(props); // no exceptions thrown, so save the valid path and exit LOG.info("Successfully loaded configuration file: " + file); config_location = file; } finally { file_stream.close(); } }
[ "protected", "void", "loadConfig", "(", "final", "String", "file", ")", "throws", "FileNotFoundException", ",", "IOException", "{", "final", "FileInputStream", "file_stream", "=", "new", "FileInputStream", "(", "file", ")", ";", "try", "{", "final", "Properties", "props", "=", "new", "Properties", "(", ")", ";", "props", ".", "load", "(", "file_stream", ")", ";", "// load the hash map", "loadHashMap", "(", "props", ")", ";", "// no exceptions thrown, so save the valid path and exit", "LOG", ".", "info", "(", "\"Successfully loaded configuration file: \"", "+", "file", ")", ";", "config_location", "=", "file", ";", "}", "finally", "{", "file_stream", ".", "close", "(", ")", ";", "}", "}" ]
Attempts to load the configuration from the given location @param file Path to the file to load @throws IOException Thrown if there was an issue reading the file @throws FileNotFoundException Thrown if the config file was not found
[ "Attempts", "to", "load", "the", "configuration", "from", "the", "given", "location" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L695-L711
13,407
OpenTSDB/opentsdb
src/utils/Config.java
Config.loadStaticVariables
public void loadStaticVariables() { auto_metric = this.getBoolean("tsd.core.auto_create_metrics"); auto_tagk = this.getBoolean("tsd.core.auto_create_tagks"); auto_tagv = this.getBoolean("tsd.core.auto_create_tagvs"); enable_compactions = this.getBoolean("tsd.storage.enable_compaction"); enable_appends = this.getBoolean("tsd.storage.enable_appends"); repair_appends = this.getBoolean("tsd.storage.repair_appends"); enable_chunked_requests = this.getBoolean("tsd.http.request.enable_chunked"); enable_realtime_ts = this.getBoolean("tsd.core.meta.enable_realtime_ts"); enable_realtime_uid = this.getBoolean("tsd.core.meta.enable_realtime_uid"); enable_tsuid_incrementing = this.getBoolean("tsd.core.meta.enable_tsuid_incrementing"); enable_tsuid_tracking = this.getBoolean("tsd.core.meta.enable_tsuid_tracking"); if (this.hasProperty("tsd.http.request.max_chunk")) { max_chunked_requests = this.getInt("tsd.http.request.max_chunk"); } if (this.hasProperty("tsd.http.header_tag")) { http_header_tag = this.getString("tsd.http.header_tag"); } enable_tree_processing = this.getBoolean("tsd.core.tree.enable_processing"); fix_duplicates = this.getBoolean("tsd.storage.fix_duplicates"); scanner_max_num_rows = this.getInt("tsd.storage.hbase.scanner.maxNumRows"); use_otsdb_timestamp = this.getBoolean("tsd.storage.use_otsdb_timestamp"); get_date_tiered_compaction_start = this.getLong("tsd.storage.get_date_tiered_compaction_start"); use_max_value = this.getBoolean("tsd.storage.use_max_value"); }
java
public void loadStaticVariables() { auto_metric = this.getBoolean("tsd.core.auto_create_metrics"); auto_tagk = this.getBoolean("tsd.core.auto_create_tagks"); auto_tagv = this.getBoolean("tsd.core.auto_create_tagvs"); enable_compactions = this.getBoolean("tsd.storage.enable_compaction"); enable_appends = this.getBoolean("tsd.storage.enable_appends"); repair_appends = this.getBoolean("tsd.storage.repair_appends"); enable_chunked_requests = this.getBoolean("tsd.http.request.enable_chunked"); enable_realtime_ts = this.getBoolean("tsd.core.meta.enable_realtime_ts"); enable_realtime_uid = this.getBoolean("tsd.core.meta.enable_realtime_uid"); enable_tsuid_incrementing = this.getBoolean("tsd.core.meta.enable_tsuid_incrementing"); enable_tsuid_tracking = this.getBoolean("tsd.core.meta.enable_tsuid_tracking"); if (this.hasProperty("tsd.http.request.max_chunk")) { max_chunked_requests = this.getInt("tsd.http.request.max_chunk"); } if (this.hasProperty("tsd.http.header_tag")) { http_header_tag = this.getString("tsd.http.header_tag"); } enable_tree_processing = this.getBoolean("tsd.core.tree.enable_processing"); fix_duplicates = this.getBoolean("tsd.storage.fix_duplicates"); scanner_max_num_rows = this.getInt("tsd.storage.hbase.scanner.maxNumRows"); use_otsdb_timestamp = this.getBoolean("tsd.storage.use_otsdb_timestamp"); get_date_tiered_compaction_start = this.getLong("tsd.storage.get_date_tiered_compaction_start"); use_max_value = this.getBoolean("tsd.storage.use_max_value"); }
[ "public", "void", "loadStaticVariables", "(", ")", "{", "auto_metric", "=", "this", ".", "getBoolean", "(", "\"tsd.core.auto_create_metrics\"", ")", ";", "auto_tagk", "=", "this", ".", "getBoolean", "(", "\"tsd.core.auto_create_tagks\"", ")", ";", "auto_tagv", "=", "this", ".", "getBoolean", "(", "\"tsd.core.auto_create_tagvs\"", ")", ";", "enable_compactions", "=", "this", ".", "getBoolean", "(", "\"tsd.storage.enable_compaction\"", ")", ";", "enable_appends", "=", "this", ".", "getBoolean", "(", "\"tsd.storage.enable_appends\"", ")", ";", "repair_appends", "=", "this", ".", "getBoolean", "(", "\"tsd.storage.repair_appends\"", ")", ";", "enable_chunked_requests", "=", "this", ".", "getBoolean", "(", "\"tsd.http.request.enable_chunked\"", ")", ";", "enable_realtime_ts", "=", "this", ".", "getBoolean", "(", "\"tsd.core.meta.enable_realtime_ts\"", ")", ";", "enable_realtime_uid", "=", "this", ".", "getBoolean", "(", "\"tsd.core.meta.enable_realtime_uid\"", ")", ";", "enable_tsuid_incrementing", "=", "this", ".", "getBoolean", "(", "\"tsd.core.meta.enable_tsuid_incrementing\"", ")", ";", "enable_tsuid_tracking", "=", "this", ".", "getBoolean", "(", "\"tsd.core.meta.enable_tsuid_tracking\"", ")", ";", "if", "(", "this", ".", "hasProperty", "(", "\"tsd.http.request.max_chunk\"", ")", ")", "{", "max_chunked_requests", "=", "this", ".", "getInt", "(", "\"tsd.http.request.max_chunk\"", ")", ";", "}", "if", "(", "this", ".", "hasProperty", "(", "\"tsd.http.header_tag\"", ")", ")", "{", "http_header_tag", "=", "this", ".", "getString", "(", "\"tsd.http.header_tag\"", ")", ";", "}", "enable_tree_processing", "=", "this", ".", "getBoolean", "(", "\"tsd.core.tree.enable_processing\"", ")", ";", "fix_duplicates", "=", "this", ".", "getBoolean", "(", "\"tsd.storage.fix_duplicates\"", ")", ";", "scanner_max_num_rows", "=", "this", ".", "getInt", "(", "\"tsd.storage.hbase.scanner.maxNumRows\"", ")", ";", "use_otsdb_timestamp", "=", "this", ".", "getBoolean", "(", "\"tsd.storage.use_otsdb_timestamp\"", ")", ";", "get_date_tiered_compaction_start", "=", "this", ".", "getLong", "(", "\"tsd.storage.get_date_tiered_compaction_start\"", ")", ";", "use_max_value", "=", "this", ".", "getBoolean", "(", "\"tsd.storage.use_max_value\"", ")", ";", "}" ]
Loads the static class variables for values that are called often. This should be called any time the configuration changes.
[ "Loads", "the", "static", "class", "variables", "for", "values", "that", "are", "called", "often", ".", "This", "should", "be", "called", "any", "time", "the", "configuration", "changes", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Config.java#L717-L743
13,408
OpenTSDB/opentsdb
src/tsd/client/QueryString.java
QueryString.add
public void add(final String name, final String value) { ArrayList<String> values = super.get(name); if (values == null) { values = new ArrayList<String>(1); // Often there's only 1 value. super.put(name, values); } values.add(value); }
java
public void add(final String name, final String value) { ArrayList<String> values = super.get(name); if (values == null) { values = new ArrayList<String>(1); // Often there's only 1 value. super.put(name, values); } values.add(value); }
[ "public", "void", "add", "(", "final", "String", "name", ",", "final", "String", "value", ")", "{", "ArrayList", "<", "String", ">", "values", "=", "super", ".", "get", "(", "name", ")", ";", "if", "(", "values", "==", "null", ")", "{", "values", "=", "new", "ArrayList", "<", "String", ">", "(", "1", ")", ";", "// Often there's only 1 value.", "super", ".", "put", "(", "name", ",", "values", ")", ";", "}", "values", ".", "add", "(", "value", ")", ";", "}" ]
Adds a query string element. @param name The name of the element. @param value The value of the element.
[ "Adds", "a", "query", "string", "element", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryString.java#L73-L80
13,409
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatPutV1
public ChannelBuffer formatPutV1(final Map<String, Object> results) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatPutV1"); }
java
public ChannelBuffer formatPutV1(final Map<String, Object> results) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatPutV1"); }
[ "public", "ChannelBuffer", "formatPutV1", "(", "final", "Map", "<", "String", ",", "Object", ">", "results", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatPutV1\"", ")", ";", "}" ]
Formats the results of an HTTP data point storage request @param results A map of results. The map will consist of: <ul><li>success - (long) the number of successfully parsed datapoints</li> <li>failed - (long) the number of datapoint parsing failures</li> <li>errors - (ArrayList&lt;HashMap&lt;String, Object&gt;&gt;) an optional list of datapoints that had errors. The nested map has these fields: <ul><li>error - (String) the error that occurred</li> <li>datapoint - (IncomingDatapoint) the datapoint that generated the error </li></ul></li></ul> @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Formats", "the", "results", "of", "an", "HTTP", "data", "point", "storage", "request" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L392-L397
13,410
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatSuggestV1
public ChannelBuffer formatSuggestV1(final List<String> suggestions) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatSuggestV1"); }
java
public ChannelBuffer formatSuggestV1(final List<String> suggestions) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatSuggestV1"); }
[ "public", "ChannelBuffer", "formatSuggestV1", "(", "final", "List", "<", "String", ">", "suggestions", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatSuggestV1\"", ")", ";", "}" ]
Formats a suggestion response @param suggestions List of suggestions for the given type @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Formats", "a", "suggestion", "response" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L405-L410
13,411
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatAggregatorsV1
public ChannelBuffer formatAggregatorsV1(final Set<String> aggregators) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatAggregatorsV1"); }
java
public ChannelBuffer formatAggregatorsV1(final Set<String> aggregators) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatAggregatorsV1"); }
[ "public", "ChannelBuffer", "formatAggregatorsV1", "(", "final", "Set", "<", "String", ">", "aggregators", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatAggregatorsV1\"", ")", ";", "}" ]
Format the list of implemented aggregators @param aggregators The list of aggregation functions @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "the", "list", "of", "implemented", "aggregators" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L430-L435
13,412
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatVersionV1
public ChannelBuffer formatVersionV1(final Map<String, String> version) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatVersionV1"); }
java
public ChannelBuffer formatVersionV1(final Map<String, String> version) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatVersionV1"); }
[ "public", "ChannelBuffer", "formatVersionV1", "(", "final", "Map", "<", "String", ",", "String", ">", "version", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatVersionV1\"", ")", ";", "}" ]
Format a hash map of information about the OpenTSDB version @param version A hash map with version information @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "hash", "map", "of", "information", "about", "the", "OpenTSDB", "version" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L443-L448
13,413
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatDropCachesV1
public ChannelBuffer formatDropCachesV1(final Map<String, String> response) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatDropCachesV1"); }
java
public ChannelBuffer formatDropCachesV1(final Map<String, String> response) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatDropCachesV1"); }
[ "public", "ChannelBuffer", "formatDropCachesV1", "(", "final", "Map", "<", "String", ",", "String", ">", "response", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatDropCachesV1\"", ")", ";", "}" ]
Format a response from the DropCaches call @param response A hash map with a response @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "response", "from", "the", "DropCaches", "call" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L456-L461
13,414
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatLastPointQueryV1
public ChannelBuffer formatLastPointQueryV1( final List<IncomingDataPoint> data_points) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatLastPointQueryV1"); }
java
public ChannelBuffer formatLastPointQueryV1( final List<IncomingDataPoint> data_points) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatLastPointQueryV1"); }
[ "public", "ChannelBuffer", "formatLastPointQueryV1", "(", "final", "List", "<", "IncomingDataPoint", ">", "data_points", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatLastPointQueryV1\"", ")", ";", "}" ]
Format a list of last data points @param data_points The results of the query @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "list", "of", "last", "data", "points" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L531-L537
13,415
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatTSMetaListV1
public ChannelBuffer formatTSMetaListV1(final List<TSMeta> metas) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatTSMetaV1"); }
java
public ChannelBuffer formatTSMetaListV1(final List<TSMeta> metas) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatTSMetaV1"); }
[ "public", "ChannelBuffer", "formatTSMetaListV1", "(", "final", "List", "<", "TSMeta", ">", "metas", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatTSMetaV1\"", ")", ";", "}" ]
Format a a list of TSMeta objects @param metas The list of TSMeta objects to serialize @return A JSON structure @throws JSONException if serialization failed
[ "Format", "a", "a", "list", "of", "TSMeta", "objects" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L571-L576
13,416
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatTreesV1
public ChannelBuffer formatTreesV1(final List<Tree> trees) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatTreesV1"); }
java
public ChannelBuffer formatTreesV1(final List<Tree> trees) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatTreesV1"); }
[ "public", "ChannelBuffer", "formatTreesV1", "(", "final", "List", "<", "Tree", ">", "trees", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatTreesV1\"", ")", ";", "}" ]
Format a list of tree objects. Note that the list may be empty if no trees were present. @param trees A list of one or more trees to serialize @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "list", "of", "tree", "objects", ".", "Note", "that", "the", "list", "may", "be", "empty", "if", "no", "trees", "were", "present", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L611-L616
13,417
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatTreeCollisionNotMatchedV1
public ChannelBuffer formatTreeCollisionNotMatchedV1( final Map<String, String> results, final boolean is_collisions) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatTreeCollisionNotMatched"); }
java
public ChannelBuffer formatTreeCollisionNotMatchedV1( final Map<String, String> results, final boolean is_collisions) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatTreeCollisionNotMatched"); }
[ "public", "ChannelBuffer", "formatTreeCollisionNotMatchedV1", "(", "final", "Map", "<", "String", ",", "String", ">", "results", ",", "final", "boolean", "is_collisions", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatTreeCollisionNotMatched\"", ")", ";", "}" ]
Format a map of one or more TSUIDs that collided or were not matched @param results The list of results. Collisions: key = tsuid, value = collided TSUID. Not Matched: key = tsuid, value = message about non matched rules. @param is_collisions Whether or the map is a collision result set (true) or a not matched set (false). @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "map", "of", "one", "or", "more", "TSUIDs", "that", "collided", "or", "were", "not", "matched" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L641-L647
13,418
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatAnnotationsV1
public ChannelBuffer formatAnnotationsV1(final List<Annotation> notes) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatAnnotationsV1"); }
java
public ChannelBuffer formatAnnotationsV1(final List<Annotation> notes) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatAnnotationsV1"); }
[ "public", "ChannelBuffer", "formatAnnotationsV1", "(", "final", "List", "<", "Annotation", ">", "notes", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatAnnotationsV1\"", ")", ";", "}" ]
Format a list of annotation objects @param notes The annotation objects to format @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "list", "of", "annotation", "objects" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L685-L690
13,419
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatStatsV1
public ChannelBuffer formatStatsV1(final List<IncomingDataPoint> stats) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatStatsV1"); }
java
public ChannelBuffer formatStatsV1(final List<IncomingDataPoint> stats) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatStatsV1"); }
[ "public", "ChannelBuffer", "formatStatsV1", "(", "final", "List", "<", "IncomingDataPoint", ">", "stats", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatStatsV1\"", ")", ";", "}" ]
Format a list of statistics @param stats The statistics list to format @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method
[ "Format", "a", "list", "of", "statistics" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L712-L717
13,420
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatThreadStatsV1
public ChannelBuffer formatThreadStatsV1(final List<Map<String, Object>> stats) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatThreadStatsV1"); }
java
public ChannelBuffer formatThreadStatsV1(final List<Map<String, Object>> stats) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatThreadStatsV1"); }
[ "public", "ChannelBuffer", "formatThreadStatsV1", "(", "final", "List", "<", "Map", "<", "String", ",", "Object", ">", ">", "stats", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatThreadStatsV1\"", ")", ";", "}" ]
Format a list of thread statistics @param stats The thread statistics list to format @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method @since 2.2
[ "Format", "a", "list", "of", "thread", "statistics" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L726-L731
13,421
OpenTSDB/opentsdb
src/tsd/HttpSerializer.java
HttpSerializer.formatQueryStatsV1
public ChannelBuffer formatQueryStatsV1(final Map<String, Object> query_stats) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatQueryStatsV1"); }
java
public ChannelBuffer formatQueryStatsV1(final Map<String, Object> query_stats) { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "The requested API endpoint has not been implemented", this.getClass().getCanonicalName() + " has not implemented formatQueryStatsV1"); }
[ "public", "ChannelBuffer", "formatQueryStatsV1", "(", "final", "Map", "<", "String", ",", "Object", ">", "query_stats", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "NOT_IMPLEMENTED", ",", "\"The requested API endpoint has not been implemented\"", ",", "this", ".", "getClass", "(", ")", ".", "getCanonicalName", "(", ")", "+", "\" has not implemented formatQueryStatsV1\"", ")", ";", "}" ]
Format the query stats @param query_stats Map of query statistics @return A ChannelBuffer object to pass on to the caller @throws BadRequestException if the plugin has not implemented this method @since 2.2
[ "Format", "the", "query", "stats" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpSerializer.java#L768-L773
13,422
OpenTSDB/opentsdb
src/utils/DateTime.java
DateTime.getDurationUnits
public static final String getDurationUnits(final String duration) { if (duration == null || duration.isEmpty()) { throw new IllegalArgumentException("Duration cannot be null or empty"); } int unit = 0; while (unit < duration.length() && Character.isDigit(duration.charAt(unit))) { unit++; } final String units = duration.substring(unit).toLowerCase(); if (units.equals("ms") || units.equals("s") || units.equals("m") || units.equals("h") || units.equals("d") || units.equals("w") || units.equals("n") || units.equals("y")) { return units; } throw new IllegalArgumentException("Invalid units in the duration: " + units); }
java
public static final String getDurationUnits(final String duration) { if (duration == null || duration.isEmpty()) { throw new IllegalArgumentException("Duration cannot be null or empty"); } int unit = 0; while (unit < duration.length() && Character.isDigit(duration.charAt(unit))) { unit++; } final String units = duration.substring(unit).toLowerCase(); if (units.equals("ms") || units.equals("s") || units.equals("m") || units.equals("h") || units.equals("d") || units.equals("w") || units.equals("n") || units.equals("y")) { return units; } throw new IllegalArgumentException("Invalid units in the duration: " + units); }
[ "public", "static", "final", "String", "getDurationUnits", "(", "final", "String", "duration", ")", "{", "if", "(", "duration", "==", "null", "||", "duration", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Duration cannot be null or empty\"", ")", ";", "}", "int", "unit", "=", "0", ";", "while", "(", "unit", "<", "duration", ".", "length", "(", ")", "&&", "Character", ".", "isDigit", "(", "duration", ".", "charAt", "(", "unit", ")", ")", ")", "{", "unit", "++", ";", "}", "final", "String", "units", "=", "duration", ".", "substring", "(", "unit", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "units", ".", "equals", "(", "\"ms\"", ")", "||", "units", ".", "equals", "(", "\"s\"", ")", "||", "units", ".", "equals", "(", "\"m\"", ")", "||", "units", ".", "equals", "(", "\"h\"", ")", "||", "units", ".", "equals", "(", "\"d\"", ")", "||", "units", ".", "equals", "(", "\"w\"", ")", "||", "units", ".", "equals", "(", "\"n\"", ")", "||", "units", ".", "equals", "(", "\"y\"", ")", ")", "{", "return", "units", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"Invalid units in the duration: \"", "+", "units", ")", ";", "}" ]
Returns the suffix or "units" of the duration as a string. The result will be ms, s, m, h, d, w, n or y. @param duration The duration in the format #units, e.g. 1d or 6h @return Just the suffix, e.g. 'd' or 'h' @throws IllegalArgumentException if the duration is null, empty or if the units are invalid. @since 2.4
[ "Returns", "the", "suffix", "or", "units", "of", "the", "duration", "as", "a", "string", ".", "The", "result", "will", "be", "ms", "s", "m", "h", "d", "w", "n", "or", "y", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/DateTime.java#L237-L253
13,423
OpenTSDB/opentsdb
src/utils/DateTime.java
DateTime.getDurationInterval
public static final int getDurationInterval(final String duration) { if (duration == null || duration.isEmpty()) { throw new IllegalArgumentException("Duration cannot be null or empty"); } if (duration.contains(".")) { throw new IllegalArgumentException("Floating point intervals are not supported"); } int unit = 0; while (Character.isDigit(duration.charAt(unit))) { unit++; } int interval; try { interval = Integer.parseInt(duration.substring(0, unit)); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid duration (number): " + duration); } if (interval <= 0) { throw new IllegalArgumentException("Zero or negative duration: " + duration); } return interval; }
java
public static final int getDurationInterval(final String duration) { if (duration == null || duration.isEmpty()) { throw new IllegalArgumentException("Duration cannot be null or empty"); } if (duration.contains(".")) { throw new IllegalArgumentException("Floating point intervals are not supported"); } int unit = 0; while (Character.isDigit(duration.charAt(unit))) { unit++; } int interval; try { interval = Integer.parseInt(duration.substring(0, unit)); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid duration (number): " + duration); } if (interval <= 0) { throw new IllegalArgumentException("Zero or negative duration: " + duration); } return interval; }
[ "public", "static", "final", "int", "getDurationInterval", "(", "final", "String", "duration", ")", "{", "if", "(", "duration", "==", "null", "||", "duration", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Duration cannot be null or empty\"", ")", ";", "}", "if", "(", "duration", ".", "contains", "(", "\".\"", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Floating point intervals are not supported\"", ")", ";", "}", "int", "unit", "=", "0", ";", "while", "(", "Character", ".", "isDigit", "(", "duration", ".", "charAt", "(", "unit", ")", ")", ")", "{", "unit", "++", ";", "}", "int", "interval", ";", "try", "{", "interval", "=", "Integer", ".", "parseInt", "(", "duration", ".", "substring", "(", "0", ",", "unit", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid duration (number): \"", "+", "duration", ")", ";", "}", "if", "(", "interval", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Zero or negative duration: \"", "+", "duration", ")", ";", "}", "return", "interval", ";", "}" ]
Parses the prefix of the duration, the interval and returns it as a number. E.g. if you supply "1d" it will return "1". If you supply "60m" it will return "60". @param duration The duration to parse in the format #units, e.g. "1d" or "60m" @return The interval as an integer, regardless of units. @throws IllegalArgumentException if the duration is null, empty or parsing of the integer failed. @since 2.4
[ "Parses", "the", "prefix", "of", "the", "duration", "the", "interval", "and", "returns", "it", "as", "a", "number", ".", "E", ".", "g", ".", "if", "you", "supply", "1d", "it", "will", "return", "1", ".", "If", "you", "supply", "60m", "it", "will", "return", "60", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/DateTime.java#L265-L286
13,424
OpenTSDB/opentsdb
src/utils/DateTime.java
DateTime.setTimeZone
public static void setTimeZone(final SimpleDateFormat fmt, final String tzname) { if (tzname == null) { return; // Use the default timezone. } final TimeZone tz = DateTime.timezones.get(tzname); if (tz != null) { fmt.setTimeZone(tz); } else { throw new IllegalArgumentException("Invalid timezone name: " + tzname); } }
java
public static void setTimeZone(final SimpleDateFormat fmt, final String tzname) { if (tzname == null) { return; // Use the default timezone. } final TimeZone tz = DateTime.timezones.get(tzname); if (tz != null) { fmt.setTimeZone(tz); } else { throw new IllegalArgumentException("Invalid timezone name: " + tzname); } }
[ "public", "static", "void", "setTimeZone", "(", "final", "SimpleDateFormat", "fmt", ",", "final", "String", "tzname", ")", "{", "if", "(", "tzname", "==", "null", ")", "{", "return", ";", "// Use the default timezone.", "}", "final", "TimeZone", "tz", "=", "DateTime", ".", "timezones", ".", "get", "(", "tzname", ")", ";", "if", "(", "tz", "!=", "null", ")", "{", "fmt", ".", "setTimeZone", "(", "tz", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid timezone name: \"", "+", "tzname", ")", ";", "}", "}" ]
Applies the given timezone to the given date format. @param fmt Date format to apply the timezone to. @param tzname Name of the timezone, or {@code null} in which case this function is a no-op. @throws IllegalArgumentException if tzname isn't a valid timezone name. @throws NullPointerException if the format is null
[ "Applies", "the", "given", "timezone", "to", "the", "given", "date", "format", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/DateTime.java#L312-L323
13,425
OpenTSDB/opentsdb
src/utils/DateTime.java
DateTime.msFromNanoDiff
public static double msFromNanoDiff(final long end, final long start) { if (end < start) { throw new IllegalArgumentException("End (" + end + ") cannot be less " + "than start (" + start + ")"); } return ((double) end - (double) start) / 1000000; }
java
public static double msFromNanoDiff(final long end, final long start) { if (end < start) { throw new IllegalArgumentException("End (" + end + ") cannot be less " + "than start (" + start + ")"); } return ((double) end - (double) start) / 1000000; }
[ "public", "static", "double", "msFromNanoDiff", "(", "final", "long", "end", ",", "final", "long", "start", ")", "{", "if", "(", "end", "<", "start", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"End (\"", "+", "end", "+", "\") cannot be less \"", "+", "\"than start (\"", "+", "start", "+", "\")\"", ")", ";", "}", "return", "(", "(", "double", ")", "end", "-", "(", "double", ")", "start", ")", "/", "1000000", ";", "}" ]
Calculates the difference between two values and returns the time in milliseconds as a double. @param end The end timestamp @param start The start timestamp @return The value in milliseconds @throws IllegalArgumentException if end is less than start @since 2.2
[ "Calculates", "the", "difference", "between", "two", "values", "and", "returns", "the", "time", "in", "milliseconds", "as", "a", "double", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/DateTime.java#L385-L391
13,426
OpenTSDB/opentsdb
src/utils/DateTime.java
DateTime.unitsToCalendarType
public static int unitsToCalendarType(final String units) { if (units == null || units.isEmpty()) { throw new IllegalArgumentException("Units cannot be null or empty"); } final String lc = units.toLowerCase(); if (lc.equals("ms")) { return Calendar.MILLISECOND; } else if (lc.equals("s")) { return Calendar.SECOND; } else if (lc.equals("m")) { return Calendar.MINUTE; } else if (lc.equals("h")) { return Calendar.HOUR_OF_DAY; } else if (lc.equals("d")) { return Calendar.DAY_OF_MONTH; } else if (lc.equals("w")) { return Calendar.DAY_OF_WEEK; } else if (lc.equals("n")) { return Calendar.MONTH; } else if (lc.equals("y")) { return Calendar.YEAR; } throw new IllegalArgumentException("Unrecognized unit type: " + units); }
java
public static int unitsToCalendarType(final String units) { if (units == null || units.isEmpty()) { throw new IllegalArgumentException("Units cannot be null or empty"); } final String lc = units.toLowerCase(); if (lc.equals("ms")) { return Calendar.MILLISECOND; } else if (lc.equals("s")) { return Calendar.SECOND; } else if (lc.equals("m")) { return Calendar.MINUTE; } else if (lc.equals("h")) { return Calendar.HOUR_OF_DAY; } else if (lc.equals("d")) { return Calendar.DAY_OF_MONTH; } else if (lc.equals("w")) { return Calendar.DAY_OF_WEEK; } else if (lc.equals("n")) { return Calendar.MONTH; } else if (lc.equals("y")) { return Calendar.YEAR; } throw new IllegalArgumentException("Unrecognized unit type: " + units); }
[ "public", "static", "int", "unitsToCalendarType", "(", "final", "String", "units", ")", "{", "if", "(", "units", "==", "null", "||", "units", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Units cannot be null or empty\"", ")", ";", "}", "final", "String", "lc", "=", "units", ".", "toLowerCase", "(", ")", ";", "if", "(", "lc", ".", "equals", "(", "\"ms\"", ")", ")", "{", "return", "Calendar", ".", "MILLISECOND", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"s\"", ")", ")", "{", "return", "Calendar", ".", "SECOND", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"m\"", ")", ")", "{", "return", "Calendar", ".", "MINUTE", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"h\"", ")", ")", "{", "return", "Calendar", ".", "HOUR_OF_DAY", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"d\"", ")", ")", "{", "return", "Calendar", ".", "DAY_OF_MONTH", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"w\"", ")", ")", "{", "return", "Calendar", ".", "DAY_OF_WEEK", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"n\"", ")", ")", "{", "return", "Calendar", ".", "MONTH", ";", "}", "else", "if", "(", "lc", ".", "equals", "(", "\"y\"", ")", ")", "{", "return", "Calendar", ".", "YEAR", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"Unrecognized unit type: \"", "+", "units", ")", ";", "}" ]
Return the proper Calendar time unit as an integer given the string @param units The unit to parse @return An integer matching a Calendar.&lt;UNIT&gt; enum @throws IllegalArgumentException if the unit is null, empty or doesn't match one of the configured units. @since 2.3
[ "Return", "the", "proper", "Calendar", "time", "unit", "as", "an", "integer", "given", "the", "string" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/DateTime.java#L616-L640
13,427
OpenTSDB/opentsdb
src/query/pojo/Output.java
Output.validate
@Override public void validate() { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("missing or empty id"); } Query.validateId(id); }
java
@Override public void validate() { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("missing or empty id"); } Query.validateId(id); }
[ "@", "Override", "public", "void", "validate", "(", ")", "{", "if", "(", "id", "==", "null", "||", "id", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"missing or empty id\"", ")", ";", "}", "Query", ".", "validateId", "(", "id", ")", ";", "}" ]
Validates the output @throws IllegalArgumentException if one or more parameters were invalid
[ "Validates", "the", "output" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/pojo/Output.java#L61-L66
13,428
OpenTSDB/opentsdb
src/core/Aggregators.java
Aggregators.get
public static Aggregator get(final String name) { final Aggregator agg = aggregators.get(name); if (agg != null) { return agg; } throw new NoSuchElementException("No such aggregator: " + name); }
java
public static Aggregator get(final String name) { final Aggregator agg = aggregators.get(name); if (agg != null) { return agg; } throw new NoSuchElementException("No such aggregator: " + name); }
[ "public", "static", "Aggregator", "get", "(", "final", "String", "name", ")", "{", "final", "Aggregator", "agg", "=", "aggregators", ".", "get", "(", "name", ")", ";", "if", "(", "agg", "!=", "null", ")", "{", "return", "agg", ";", "}", "throw", "new", "NoSuchElementException", "(", "\"No such aggregator: \"", "+", "name", ")", ";", "}" ]
Returns the aggregator corresponding to the given name. @param name The name of the aggregator to get. @throws NoSuchElementException if the given name doesn't exist. @see #set
[ "Returns", "the", "aggregator", "corresponding", "to", "the", "given", "name", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Aggregators.java#L222-L228
13,429
OpenTSDB/opentsdb
src/meta/Annotation.java
Annotation.delete
public Deferred<Object> delete(final TSDB tsdb) { if (start_time < 1) { throw new IllegalArgumentException("The start timestamp has not been set"); } final byte[] tsuid_byte = tsuid != null && !tsuid.isEmpty() ? UniqueId.stringToUid(tsuid) : null; final DeleteRequest delete = new DeleteRequest(tsdb.dataTable(), getRowKey(start_time, tsuid_byte), FAMILY, getQualifier(start_time)); return tsdb.getClient().delete(delete); }
java
public Deferred<Object> delete(final TSDB tsdb) { if (start_time < 1) { throw new IllegalArgumentException("The start timestamp has not been set"); } final byte[] tsuid_byte = tsuid != null && !tsuid.isEmpty() ? UniqueId.stringToUid(tsuid) : null; final DeleteRequest delete = new DeleteRequest(tsdb.dataTable(), getRowKey(start_time, tsuid_byte), FAMILY, getQualifier(start_time)); return tsdb.getClient().delete(delete); }
[ "public", "Deferred", "<", "Object", ">", "delete", "(", "final", "TSDB", "tsdb", ")", "{", "if", "(", "start_time", "<", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The start timestamp has not been set\"", ")", ";", "}", "final", "byte", "[", "]", "tsuid_byte", "=", "tsuid", "!=", "null", "&&", "!", "tsuid", ".", "isEmpty", "(", ")", "?", "UniqueId", ".", "stringToUid", "(", "tsuid", ")", ":", "null", ";", "final", "DeleteRequest", "delete", "=", "new", "DeleteRequest", "(", "tsdb", ".", "dataTable", "(", ")", ",", "getRowKey", "(", "start_time", ",", "tsuid_byte", ")", ",", "FAMILY", ",", "getQualifier", "(", "start_time", ")", ")", ";", "return", "tsdb", ".", "getClient", "(", ")", ".", "delete", "(", "delete", ")", ";", "}" ]
Attempts to mark an Annotation object for deletion. Note that if the annoation does not exist in storage, this delete call will not throw an error. @param tsdb The TSDB to use for storage access @return A meaningless Deferred for the caller to wait on until the call is complete. The value may be null.
[ "Attempts", "to", "mark", "an", "Annotation", "object", "for", "deletion", ".", "Note", "that", "if", "the", "annoation", "does", "not", "exist", "in", "storage", "this", "delete", "call", "will", "not", "throw", "an", "error", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/Annotation.java#L212-L223
13,430
OpenTSDB/opentsdb
src/meta/Annotation.java
Annotation.getAnnotation
public static Deferred<Annotation> getAnnotation(final TSDB tsdb, final long start_time) { return getAnnotation(tsdb, (byte[])null, start_time); }
java
public static Deferred<Annotation> getAnnotation(final TSDB tsdb, final long start_time) { return getAnnotation(tsdb, (byte[])null, start_time); }
[ "public", "static", "Deferred", "<", "Annotation", ">", "getAnnotation", "(", "final", "TSDB", "tsdb", ",", "final", "long", "start_time", ")", "{", "return", "getAnnotation", "(", "tsdb", ",", "(", "byte", "[", "]", ")", "null", ",", "start_time", ")", ";", "}" ]
Attempts to fetch a global annotation from storage @param tsdb The TSDB to use for storage access @param start_time The start time as a Unix epoch timestamp @return A valid annotation object if found, null if not
[ "Attempts", "to", "fetch", "a", "global", "annotation", "from", "storage" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/Annotation.java#L231-L234
13,431
OpenTSDB/opentsdb
src/meta/Annotation.java
Annotation.getGlobalAnnotations
public static Deferred<List<Annotation>> getGlobalAnnotations(final TSDB tsdb, final long start_time, final long end_time) { if (end_time < 1) { throw new IllegalArgumentException("The end timestamp has not been set"); } if (end_time < start_time) { throw new IllegalArgumentException( "The end timestamp cannot be less than the start timestamp"); } /** * Scanner that loops through the [0, 0, 0, timestamp] rows looking for * global annotations. Returns a list of parsed annotation objects. * The list may be empty. */ final class ScannerCB implements Callback<Deferred<List<Annotation>>, ArrayList<ArrayList<KeyValue>>> { final Scanner scanner; final ArrayList<Annotation> annotations = new ArrayList<Annotation>(); /** * Initializes the scanner */ public ScannerCB() { final byte[] start = new byte[Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES]; final byte[] end = new byte[Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES]; final long normalized_start = (start_time - (start_time % Const.MAX_TIMESPAN)); final long normalized_end = (end_time - (end_time % Const.MAX_TIMESPAN) + Const.MAX_TIMESPAN); Bytes.setInt(start, (int) normalized_start, Const.SALT_WIDTH() + TSDB.metrics_width()); Bytes.setInt(end, (int) normalized_end, Const.SALT_WIDTH() + TSDB.metrics_width()); scanner = tsdb.getClient().newScanner(tsdb.dataTable()); scanner.setStartKey(start); scanner.setStopKey(end); scanner.setFamily(FAMILY); } public Deferred<List<Annotation>> scan() { return scanner.nextRows().addCallbackDeferring(this); } @Override public Deferred<List<Annotation>> call ( final ArrayList<ArrayList<KeyValue>> rows) throws Exception { if (rows == null || rows.isEmpty()) { return Deferred.fromResult((List<Annotation>)annotations); } for (final ArrayList<KeyValue> row : rows) { for (KeyValue column : row) { if ((column.qualifier().length == 3 || column.qualifier().length == 5) && column.qualifier()[0] == PREFIX()) { Annotation note = JSON.parseToObject(column.value(), Annotation.class); if (note.start_time < start_time || note.end_time > end_time) { continue; } annotations.add(note); } } } return scan(); } } return new ScannerCB().scan(); }
java
public static Deferred<List<Annotation>> getGlobalAnnotations(final TSDB tsdb, final long start_time, final long end_time) { if (end_time < 1) { throw new IllegalArgumentException("The end timestamp has not been set"); } if (end_time < start_time) { throw new IllegalArgumentException( "The end timestamp cannot be less than the start timestamp"); } /** * Scanner that loops through the [0, 0, 0, timestamp] rows looking for * global annotations. Returns a list of parsed annotation objects. * The list may be empty. */ final class ScannerCB implements Callback<Deferred<List<Annotation>>, ArrayList<ArrayList<KeyValue>>> { final Scanner scanner; final ArrayList<Annotation> annotations = new ArrayList<Annotation>(); /** * Initializes the scanner */ public ScannerCB() { final byte[] start = new byte[Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES]; final byte[] end = new byte[Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES]; final long normalized_start = (start_time - (start_time % Const.MAX_TIMESPAN)); final long normalized_end = (end_time - (end_time % Const.MAX_TIMESPAN) + Const.MAX_TIMESPAN); Bytes.setInt(start, (int) normalized_start, Const.SALT_WIDTH() + TSDB.metrics_width()); Bytes.setInt(end, (int) normalized_end, Const.SALT_WIDTH() + TSDB.metrics_width()); scanner = tsdb.getClient().newScanner(tsdb.dataTable()); scanner.setStartKey(start); scanner.setStopKey(end); scanner.setFamily(FAMILY); } public Deferred<List<Annotation>> scan() { return scanner.nextRows().addCallbackDeferring(this); } @Override public Deferred<List<Annotation>> call ( final ArrayList<ArrayList<KeyValue>> rows) throws Exception { if (rows == null || rows.isEmpty()) { return Deferred.fromResult((List<Annotation>)annotations); } for (final ArrayList<KeyValue> row : rows) { for (KeyValue column : row) { if ((column.qualifier().length == 3 || column.qualifier().length == 5) && column.qualifier()[0] == PREFIX()) { Annotation note = JSON.parseToObject(column.value(), Annotation.class); if (note.start_time < start_time || note.end_time > end_time) { continue; } annotations.add(note); } } } return scan(); } } return new ScannerCB().scan(); }
[ "public", "static", "Deferred", "<", "List", "<", "Annotation", ">", ">", "getGlobalAnnotations", "(", "final", "TSDB", "tsdb", ",", "final", "long", "start_time", ",", "final", "long", "end_time", ")", "{", "if", "(", "end_time", "<", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The end timestamp has not been set\"", ")", ";", "}", "if", "(", "end_time", "<", "start_time", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The end timestamp cannot be less than the start timestamp\"", ")", ";", "}", "/**\n * Scanner that loops through the [0, 0, 0, timestamp] rows looking for\n * global annotations. Returns a list of parsed annotation objects.\n * The list may be empty.\n */", "final", "class", "ScannerCB", "implements", "Callback", "<", "Deferred", "<", "List", "<", "Annotation", ">", ">", ",", "ArrayList", "<", "ArrayList", "<", "KeyValue", ">", ">", ">", "{", "final", "Scanner", "scanner", ";", "final", "ArrayList", "<", "Annotation", ">", "annotations", "=", "new", "ArrayList", "<", "Annotation", ">", "(", ")", ";", "/**\n * Initializes the scanner\n */", "public", "ScannerCB", "(", ")", "{", "final", "byte", "[", "]", "start", "=", "new", "byte", "[", "Const", ".", "SALT_WIDTH", "(", ")", "+", "TSDB", ".", "metrics_width", "(", ")", "+", "Const", ".", "TIMESTAMP_BYTES", "]", ";", "final", "byte", "[", "]", "end", "=", "new", "byte", "[", "Const", ".", "SALT_WIDTH", "(", ")", "+", "TSDB", ".", "metrics_width", "(", ")", "+", "Const", ".", "TIMESTAMP_BYTES", "]", ";", "final", "long", "normalized_start", "=", "(", "start_time", "-", "(", "start_time", "%", "Const", ".", "MAX_TIMESPAN", ")", ")", ";", "final", "long", "normalized_end", "=", "(", "end_time", "-", "(", "end_time", "%", "Const", ".", "MAX_TIMESPAN", ")", "+", "Const", ".", "MAX_TIMESPAN", ")", ";", "Bytes", ".", "setInt", "(", "start", ",", "(", "int", ")", "normalized_start", ",", "Const", ".", "SALT_WIDTH", "(", ")", "+", "TSDB", ".", "metrics_width", "(", ")", ")", ";", "Bytes", ".", "setInt", "(", "end", ",", "(", "int", ")", "normalized_end", ",", "Const", ".", "SALT_WIDTH", "(", ")", "+", "TSDB", ".", "metrics_width", "(", ")", ")", ";", "scanner", "=", "tsdb", ".", "getClient", "(", ")", ".", "newScanner", "(", "tsdb", ".", "dataTable", "(", ")", ")", ";", "scanner", ".", "setStartKey", "(", "start", ")", ";", "scanner", ".", "setStopKey", "(", "end", ")", ";", "scanner", ".", "setFamily", "(", "FAMILY", ")", ";", "}", "public", "Deferred", "<", "List", "<", "Annotation", ">", ">", "scan", "(", ")", "{", "return", "scanner", ".", "nextRows", "(", ")", ".", "addCallbackDeferring", "(", "this", ")", ";", "}", "@", "Override", "public", "Deferred", "<", "List", "<", "Annotation", ">", ">", "call", "(", "final", "ArrayList", "<", "ArrayList", "<", "KeyValue", ">", ">", "rows", ")", "throws", "Exception", "{", "if", "(", "rows", "==", "null", "||", "rows", ".", "isEmpty", "(", ")", ")", "{", "return", "Deferred", ".", "fromResult", "(", "(", "List", "<", "Annotation", ">", ")", "annotations", ")", ";", "}", "for", "(", "final", "ArrayList", "<", "KeyValue", ">", "row", ":", "rows", ")", "{", "for", "(", "KeyValue", "column", ":", "row", ")", "{", "if", "(", "(", "column", ".", "qualifier", "(", ")", ".", "length", "==", "3", "||", "column", ".", "qualifier", "(", ")", ".", "length", "==", "5", ")", "&&", "column", ".", "qualifier", "(", ")", "[", "0", "]", "==", "PREFIX", "(", ")", ")", "{", "Annotation", "note", "=", "JSON", ".", "parseToObject", "(", "column", ".", "value", "(", ")", ",", "Annotation", ".", "class", ")", ";", "if", "(", "note", ".", "start_time", "<", "start_time", "||", "note", ".", "end_time", ">", "end_time", ")", "{", "continue", ";", "}", "annotations", ".", "add", "(", "note", ")", ";", "}", "}", "}", "return", "scan", "(", ")", ";", "}", "}", "return", "new", "ScannerCB", "(", ")", ".", "scan", "(", ")", ";", "}" ]
Scans through the global annotation storage rows and returns a list of parsed annotation objects. If no annotations were found for the given timespan, the resulting list will be empty. @param tsdb The TSDB to use for storage access @param start_time Start time to scan from. May be 0 @param end_time End time to scan to. Must be greater than 0 @return A list with detected annotations. May be empty. @throws IllegalArgumentException if the end timestamp has not been set or the end time is less than the start time
[ "Scans", "through", "the", "global", "annotation", "storage", "rows", "and", "returns", "a", "list", "of", "parsed", "annotation", "objects", ".", "If", "no", "annotations", "were", "found", "for", "the", "given", "timespan", "the", "resulting", "list", "will", "be", "empty", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/Annotation.java#L304-L382
13,432
OpenTSDB/opentsdb
src/meta/Annotation.java
Annotation.timeFromQualifier
private static long timeFromQualifier(final byte[] qualifier, final long base_time) { final long offset; if (qualifier.length == 3) { offset = Bytes.getUnsignedShort(qualifier, 1); return (base_time + offset) * 1000; } else { offset = Bytes.getUnsignedInt(qualifier, 1); return (base_time * 1000) + offset; } }
java
private static long timeFromQualifier(final byte[] qualifier, final long base_time) { final long offset; if (qualifier.length == 3) { offset = Bytes.getUnsignedShort(qualifier, 1); return (base_time + offset) * 1000; } else { offset = Bytes.getUnsignedInt(qualifier, 1); return (base_time * 1000) + offset; } }
[ "private", "static", "long", "timeFromQualifier", "(", "final", "byte", "[", "]", "qualifier", ",", "final", "long", "base_time", ")", "{", "final", "long", "offset", ";", "if", "(", "qualifier", ".", "length", "==", "3", ")", "{", "offset", "=", "Bytes", ".", "getUnsignedShort", "(", "qualifier", ",", "1", ")", ";", "return", "(", "base_time", "+", "offset", ")", "*", "1000", ";", "}", "else", "{", "offset", "=", "Bytes", ".", "getUnsignedInt", "(", "qualifier", ",", "1", ")", ";", "return", "(", "base_time", "*", "1000", ")", "+", "offset", ";", "}", "}" ]
Returns a timestamp after parsing an annotation qualifier. @param qualifier The full qualifier (including prefix) on either 3 or 5 bytes @param base_time The base time from the row in seconds @return A timestamp in milliseconds @since 2.1
[ "Returns", "a", "timestamp", "after", "parsing", "an", "annotation", "qualifier", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/Annotation.java#L638-L648
13,433
OpenTSDB/opentsdb
src/core/IncomingDataPoints.java
IncomingDataPoints.checkMetricAndTags
static void checkMetricAndTags(final String metric, final Map<String, String> tags) { if (tags.size() <= 0) { throw new IllegalArgumentException("Need at least one tag (metric=" + metric + ", tags=" + tags + ')'); } else if (tags.size() > Const.MAX_NUM_TAGS()) { throw new IllegalArgumentException("Too many tags: " + tags.size() + " maximum allowed: " + Const.MAX_NUM_TAGS() + ", tags: " + tags); } Tags.validateString("metric name", metric); for (final Map.Entry<String, String> tag : tags.entrySet()) { Tags.validateString("tag name with value [" + tag.getValue() + "]", tag.getKey()); Tags.validateString("tag value with key [" + tag.getKey() + "]", tag.getValue()); } }
java
static void checkMetricAndTags(final String metric, final Map<String, String> tags) { if (tags.size() <= 0) { throw new IllegalArgumentException("Need at least one tag (metric=" + metric + ", tags=" + tags + ')'); } else if (tags.size() > Const.MAX_NUM_TAGS()) { throw new IllegalArgumentException("Too many tags: " + tags.size() + " maximum allowed: " + Const.MAX_NUM_TAGS() + ", tags: " + tags); } Tags.validateString("metric name", metric); for (final Map.Entry<String, String> tag : tags.entrySet()) { Tags.validateString("tag name with value [" + tag.getValue() + "]", tag.getKey()); Tags.validateString("tag value with key [" + tag.getKey() + "]", tag.getValue()); } }
[ "static", "void", "checkMetricAndTags", "(", "final", "String", "metric", ",", "final", "Map", "<", "String", ",", "String", ">", "tags", ")", "{", "if", "(", "tags", ".", "size", "(", ")", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Need at least one tag (metric=\"", "+", "metric", "+", "\", tags=\"", "+", "tags", "+", "'", "'", ")", ";", "}", "else", "if", "(", "tags", ".", "size", "(", ")", ">", "Const", ".", "MAX_NUM_TAGS", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Too many tags: \"", "+", "tags", ".", "size", "(", ")", "+", "\" maximum allowed: \"", "+", "Const", ".", "MAX_NUM_TAGS", "(", ")", "+", "\", tags: \"", "+", "tags", ")", ";", "}", "Tags", ".", "validateString", "(", "\"metric name\"", ",", "metric", ")", ";", "for", "(", "final", "Map", ".", "Entry", "<", "String", ",", "String", ">", "tag", ":", "tags", ".", "entrySet", "(", ")", ")", "{", "Tags", ".", "validateString", "(", "\"tag name with value [\"", "+", "tag", ".", "getValue", "(", ")", "+", "\"]\"", ",", "tag", ".", "getKey", "(", ")", ")", ";", "Tags", ".", "validateString", "(", "\"tag value with key [\"", "+", "tag", ".", "getKey", "(", ")", "+", "\"]\"", ",", "tag", ".", "getValue", "(", ")", ")", ";", "}", "}" ]
Validates the given metric and tags. @throws IllegalArgumentException if any of the arguments aren't valid.
[ "Validates", "the", "given", "metric", "and", "tags", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/IncomingDataPoints.java#L104-L121
13,434
OpenTSDB/opentsdb
src/core/IncomingDataPoints.java
IncomingDataPoints.copyInRowKey
private static void copyInRowKey(final byte[] row, final short offset, final byte[] bytes) { System.arraycopy(bytes, 0, row, offset, bytes.length); }
java
private static void copyInRowKey(final byte[] row, final short offset, final byte[] bytes) { System.arraycopy(bytes, 0, row, offset, bytes.length); }
[ "private", "static", "void", "copyInRowKey", "(", "final", "byte", "[", "]", "row", ",", "final", "short", "offset", ",", "final", "byte", "[", "]", "bytes", ")", "{", "System", ".", "arraycopy", "(", "bytes", ",", "0", ",", "row", ",", "offset", ",", "bytes", ".", "length", ")", ";", "}" ]
Copies the specified byte array at the specified offset in the row key. @param row The row key into which to copy the bytes. @param offset The offset in the row key to start writing at. @param bytes The bytes to copy.
[ "Copies", "the", "specified", "byte", "array", "at", "the", "specified", "offset", "in", "the", "row", "key", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/IncomingDataPoints.java#L233-L236
13,435
OpenTSDB/opentsdb
src/core/IncomingDataPoints.java
IncomingDataPoints.updateBaseTime
private long updateBaseTime(final long timestamp) { // We force the starting timestamp to be on a MAX_TIMESPAN boundary // so that all TSDs create rows with the same base time. Otherwise // we'd need to coordinate TSDs to avoid creating rows that cover // overlapping time periods. final long base_time = timestamp - (timestamp % Const.MAX_TIMESPAN); // Clone the row key since we're going to change it. We must clone it // because the HBase client may still hold a reference to it in its // internal datastructures. row = Arrays.copyOf(row, row.length); Bytes.setInt(row, (int) base_time, Const.SALT_WIDTH() + tsdb.metrics.width()); RowKey.prefixKeyWithSalt(row); // in case the timestamp will be involved in // salting later tsdb.scheduleForCompaction(row, (int) base_time); return base_time; }
java
private long updateBaseTime(final long timestamp) { // We force the starting timestamp to be on a MAX_TIMESPAN boundary // so that all TSDs create rows with the same base time. Otherwise // we'd need to coordinate TSDs to avoid creating rows that cover // overlapping time periods. final long base_time = timestamp - (timestamp % Const.MAX_TIMESPAN); // Clone the row key since we're going to change it. We must clone it // because the HBase client may still hold a reference to it in its // internal datastructures. row = Arrays.copyOf(row, row.length); Bytes.setInt(row, (int) base_time, Const.SALT_WIDTH() + tsdb.metrics.width()); RowKey.prefixKeyWithSalt(row); // in case the timestamp will be involved in // salting later tsdb.scheduleForCompaction(row, (int) base_time); return base_time; }
[ "private", "long", "updateBaseTime", "(", "final", "long", "timestamp", ")", "{", "// We force the starting timestamp to be on a MAX_TIMESPAN boundary", "// so that all TSDs create rows with the same base time. Otherwise", "// we'd need to coordinate TSDs to avoid creating rows that cover", "// overlapping time periods.", "final", "long", "base_time", "=", "timestamp", "-", "(", "timestamp", "%", "Const", ".", "MAX_TIMESPAN", ")", ";", "// Clone the row key since we're going to change it. We must clone it", "// because the HBase client may still hold a reference to it in its", "// internal datastructures.", "row", "=", "Arrays", ".", "copyOf", "(", "row", ",", "row", ".", "length", ")", ";", "Bytes", ".", "setInt", "(", "row", ",", "(", "int", ")", "base_time", ",", "Const", ".", "SALT_WIDTH", "(", ")", "+", "tsdb", ".", "metrics", ".", "width", "(", ")", ")", ";", "RowKey", ".", "prefixKeyWithSalt", "(", "row", ")", ";", "// in case the timestamp will be involved in", "// salting later", "tsdb", ".", "scheduleForCompaction", "(", "row", ",", "(", "int", ")", "base_time", ")", ";", "return", "base_time", ";", "}" ]
Updates the base time in the row key. @param timestamp The timestamp from which to derive the new base time. @return The updated base time.
[ "Updates", "the", "base", "time", "in", "the", "row", "key", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/IncomingDataPoints.java#L245-L260
13,436
OpenTSDB/opentsdb
src/query/expression/ExpressionFactory.java
ExpressionFactory.addTSDBFunctions
public static void addTSDBFunctions(final TSDB tsdb) { available_functions.put("divideSeries", new DivideSeries(tsdb)); available_functions.put("divide", new DivideSeries(tsdb)); available_functions.put("sumSeries", new SumSeries(tsdb)); available_functions.put("sum", new SumSeries(tsdb)); available_functions.put("diffSeries", new DiffSeries(tsdb)); available_functions.put("difference", new DiffSeries(tsdb)); available_functions.put("multiplySeries", new MultiplySeries(tsdb)); available_functions.put("multiply", new MultiplySeries(tsdb)); }
java
public static void addTSDBFunctions(final TSDB tsdb) { available_functions.put("divideSeries", new DivideSeries(tsdb)); available_functions.put("divide", new DivideSeries(tsdb)); available_functions.put("sumSeries", new SumSeries(tsdb)); available_functions.put("sum", new SumSeries(tsdb)); available_functions.put("diffSeries", new DiffSeries(tsdb)); available_functions.put("difference", new DiffSeries(tsdb)); available_functions.put("multiplySeries", new MultiplySeries(tsdb)); available_functions.put("multiply", new MultiplySeries(tsdb)); }
[ "public", "static", "void", "addTSDBFunctions", "(", "final", "TSDB", "tsdb", ")", "{", "available_functions", ".", "put", "(", "\"divideSeries\"", ",", "new", "DivideSeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"divide\"", ",", "new", "DivideSeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"sumSeries\"", ",", "new", "SumSeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"sum\"", ",", "new", "SumSeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"diffSeries\"", ",", "new", "DiffSeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"difference\"", ",", "new", "DiffSeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"multiplySeries\"", ",", "new", "MultiplySeries", "(", "tsdb", ")", ")", ";", "available_functions", ".", "put", "(", "\"multiply\"", ",", "new", "MultiplySeries", "(", "tsdb", ")", ")", ";", "}" ]
Adds more functions to the map that depend on an instantiated TSDB object. Only call this once please. @param tsdb The TSDB object to initialize with
[ "Adds", "more", "functions", "to", "the", "map", "that", "depend", "on", "an", "instantiated", "TSDB", "object", ".", "Only", "call", "this", "once", "please", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/ExpressionFactory.java#L50-L59
13,437
OpenTSDB/opentsdb
src/query/expression/ExpressionFactory.java
ExpressionFactory.getByName
public static Expression getByName(final String function) { final Expression expression = available_functions.get(function); if (expression == null) { throw new UnsupportedOperationException("Function " + function + " has not been implemented"); } return expression; }
java
public static Expression getByName(final String function) { final Expression expression = available_functions.get(function); if (expression == null) { throw new UnsupportedOperationException("Function " + function + " has not been implemented"); } return expression; }
[ "public", "static", "Expression", "getByName", "(", "final", "String", "function", ")", "{", "final", "Expression", "expression", "=", "available_functions", ".", "get", "(", "function", ")", ";", "if", "(", "expression", "==", "null", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Function \"", "+", "function", "+", "\" has not been implemented\"", ")", ";", "}", "return", "expression", ";", "}" ]
Returns the expression function given the name @param function The name of the expression to use @return The expression when located @throws UnsupportedOperationException if the requested function hasn't been stored in the map.
[ "Returns", "the", "expression", "function", "given", "the", "name" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/ExpressionFactory.java#L87-L94
13,438
OpenTSDB/opentsdb
src/rollup/RollupSeq.java
RollupSeq.setRow
public void setRow(final KeyValue column) { //This api will be called only with the KeyValues from rollup table, as per //the scan logic if (key != null) { throw new IllegalStateException("setRow was already called on " + this); } key = column.key(); //Check whether the cell is generated by same rollup aggregator if (need_count) { System.out.println("AGG ID: " + agg_id + " COUNT ID: " + count_id + " MASK: " + (column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK)); if ((column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK) == agg_id) { append(column, false, false); } else if ((column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK) == count_id) { append(column, true, false); // OLD style for Yahoo! } else if (Bytes.memcmp(RollupQuery.SUM, column.qualifier(), 0, RollupQuery.SUM.length) == 0) { append(column, false, true); } else if (Bytes.memcmp(RollupQuery.COUNT, column.qualifier(), 0, RollupQuery.COUNT.length) == 0) { append(column, true, true); } else { throw new IllegalDataException("Attempt to add a different aggrregate cell =" + column + ", expected aggregator either SUM or COUNT"); } } else { if ((column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK) == agg_id) { append(column, false, false); } else if (Bytes.memcmp(column.qualifier(), rollup_query.getRollupAggPrefix(), 0, rollup_query.getRollupAggPrefix().length) == 0) { append(column, false, true); } else { throw new IllegalDataException("Attempt to add a different aggrregate cell =" + column + ", expected aggregator " + Bytes.pretty( rollup_query.getRollupAggPrefix())); } } }
java
public void setRow(final KeyValue column) { //This api will be called only with the KeyValues from rollup table, as per //the scan logic if (key != null) { throw new IllegalStateException("setRow was already called on " + this); } key = column.key(); //Check whether the cell is generated by same rollup aggregator if (need_count) { System.out.println("AGG ID: " + agg_id + " COUNT ID: " + count_id + " MASK: " + (column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK)); if ((column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK) == agg_id) { append(column, false, false); } else if ((column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK) == count_id) { append(column, true, false); // OLD style for Yahoo! } else if (Bytes.memcmp(RollupQuery.SUM, column.qualifier(), 0, RollupQuery.SUM.length) == 0) { append(column, false, true); } else if (Bytes.memcmp(RollupQuery.COUNT, column.qualifier(), 0, RollupQuery.COUNT.length) == 0) { append(column, true, true); } else { throw new IllegalDataException("Attempt to add a different aggrregate cell =" + column + ", expected aggregator either SUM or COUNT"); } } else { if ((column.qualifier()[0] & RollupUtils.AGGREGATOR_MASK) == agg_id) { append(column, false, false); } else if (Bytes.memcmp(column.qualifier(), rollup_query.getRollupAggPrefix(), 0, rollup_query.getRollupAggPrefix().length) == 0) { append(column, false, true); } else { throw new IllegalDataException("Attempt to add a different aggrregate cell =" + column + ", expected aggregator " + Bytes.pretty( rollup_query.getRollupAggPrefix())); } } }
[ "public", "void", "setRow", "(", "final", "KeyValue", "column", ")", "{", "//This api will be called only with the KeyValues from rollup table, as per", "//the scan logic", "if", "(", "key", "!=", "null", ")", "{", "throw", "new", "IllegalStateException", "(", "\"setRow was already called on \"", "+", "this", ")", ";", "}", "key", "=", "column", ".", "key", "(", ")", ";", "//Check whether the cell is generated by same rollup aggregator", "if", "(", "need_count", ")", "{", "System", ".", "out", ".", "println", "(", "\"AGG ID: \"", "+", "agg_id", "+", "\" COUNT ID: \"", "+", "count_id", "+", "\" MASK: \"", "+", "(", "column", ".", "qualifier", "(", ")", "[", "0", "]", "&", "RollupUtils", ".", "AGGREGATOR_MASK", ")", ")", ";", "if", "(", "(", "column", ".", "qualifier", "(", ")", "[", "0", "]", "&", "RollupUtils", ".", "AGGREGATOR_MASK", ")", "==", "agg_id", ")", "{", "append", "(", "column", ",", "false", ",", "false", ")", ";", "}", "else", "if", "(", "(", "column", ".", "qualifier", "(", ")", "[", "0", "]", "&", "RollupUtils", ".", "AGGREGATOR_MASK", ")", "==", "count_id", ")", "{", "append", "(", "column", ",", "true", ",", "false", ")", ";", "// OLD style for Yahoo!", "}", "else", "if", "(", "Bytes", ".", "memcmp", "(", "RollupQuery", ".", "SUM", ",", "column", ".", "qualifier", "(", ")", ",", "0", ",", "RollupQuery", ".", "SUM", ".", "length", ")", "==", "0", ")", "{", "append", "(", "column", ",", "false", ",", "true", ")", ";", "}", "else", "if", "(", "Bytes", ".", "memcmp", "(", "RollupQuery", ".", "COUNT", ",", "column", ".", "qualifier", "(", ")", ",", "0", ",", "RollupQuery", ".", "COUNT", ".", "length", ")", "==", "0", ")", "{", "append", "(", "column", ",", "true", ",", "true", ")", ";", "}", "else", "{", "throw", "new", "IllegalDataException", "(", "\"Attempt to add a different aggrregate cell =\"", "+", "column", "+", "\", expected aggregator either SUM or COUNT\"", ")", ";", "}", "}", "else", "{", "if", "(", "(", "column", ".", "qualifier", "(", ")", "[", "0", "]", "&", "RollupUtils", ".", "AGGREGATOR_MASK", ")", "==", "agg_id", ")", "{", "append", "(", "column", ",", "false", ",", "false", ")", ";", "}", "else", "if", "(", "Bytes", ".", "memcmp", "(", "column", ".", "qualifier", "(", ")", ",", "rollup_query", ".", "getRollupAggPrefix", "(", ")", ",", "0", ",", "rollup_query", ".", "getRollupAggPrefix", "(", ")", ".", "length", ")", "==", "0", ")", "{", "append", "(", "column", ",", "false", ",", "true", ")", ";", "}", "else", "{", "throw", "new", "IllegalDataException", "(", "\"Attempt to add a different aggrregate cell =\"", "+", "column", "+", "\", expected aggregator \"", "+", "Bytes", ".", "pretty", "(", "rollup_query", ".", "getRollupAggPrefix", "(", ")", ")", ")", ";", "}", "}", "}" ]
Sets the row this instance holds in RAM using a row from a scanner. @param column The compacted HBase row to set. @throws IllegalStateException if this method was already called.
[ "Sets", "the", "row", "this", "instance", "holds", "in", "RAM", "using", "a", "row", "from", "a", "scanner", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/rollup/RollupSeq.java#L126-L163
13,439
OpenTSDB/opentsdb
src/tools/Search.java
Search.main
public static void main(String[] args) throws Exception { ArgP argp = new ArgP(); CliOptions.addCommon(argp); argp.addOption("--use-data-table", "Scan against the raw data table instead of the meta data table."); args = CliOptions.parse(argp, args); if (args == null) { usage(argp, "Invalid usage"); System.exit(2); } else if (args.length < 1) { usage(argp, "Not enough arguments"); System.exit(2); } final boolean use_data_table = argp.has("--use-data-table"); Config config = CliOptions.getConfig(argp); final TSDB tsdb = new TSDB(config); tsdb.checkNecessaryTablesExist().joinUninterruptibly(); int rc; try { rc = runCommand(tsdb, use_data_table, args); } finally { try { tsdb.getClient().shutdown().joinUninterruptibly(); LOG.info("Gracefully shutdown the TSD"); } catch (Exception e) { LOG.error("Unexpected exception while shutting down", e); rc = 42; } } System.exit(rc); }
java
public static void main(String[] args) throws Exception { ArgP argp = new ArgP(); CliOptions.addCommon(argp); argp.addOption("--use-data-table", "Scan against the raw data table instead of the meta data table."); args = CliOptions.parse(argp, args); if (args == null) { usage(argp, "Invalid usage"); System.exit(2); } else if (args.length < 1) { usage(argp, "Not enough arguments"); System.exit(2); } final boolean use_data_table = argp.has("--use-data-table"); Config config = CliOptions.getConfig(argp); final TSDB tsdb = new TSDB(config); tsdb.checkNecessaryTablesExist().joinUninterruptibly(); int rc; try { rc = runCommand(tsdb, use_data_table, args); } finally { try { tsdb.getClient().shutdown().joinUninterruptibly(); LOG.info("Gracefully shutdown the TSD"); } catch (Exception e) { LOG.error("Unexpected exception while shutting down", e); rc = 42; } } System.exit(rc); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "ArgP", "argp", "=", "new", "ArgP", "(", ")", ";", "CliOptions", ".", "addCommon", "(", "argp", ")", ";", "argp", ".", "addOption", "(", "\"--use-data-table\"", ",", "\"Scan against the raw data table instead of the meta data table.\"", ")", ";", "args", "=", "CliOptions", ".", "parse", "(", "argp", ",", "args", ")", ";", "if", "(", "args", "==", "null", ")", "{", "usage", "(", "argp", ",", "\"Invalid usage\"", ")", ";", "System", ".", "exit", "(", "2", ")", ";", "}", "else", "if", "(", "args", ".", "length", "<", "1", ")", "{", "usage", "(", "argp", ",", "\"Not enough arguments\"", ")", ";", "System", ".", "exit", "(", "2", ")", ";", "}", "final", "boolean", "use_data_table", "=", "argp", ".", "has", "(", "\"--use-data-table\"", ")", ";", "Config", "config", "=", "CliOptions", ".", "getConfig", "(", "argp", ")", ";", "final", "TSDB", "tsdb", "=", "new", "TSDB", "(", "config", ")", ";", "tsdb", ".", "checkNecessaryTablesExist", "(", ")", ".", "joinUninterruptibly", "(", ")", ";", "int", "rc", ";", "try", "{", "rc", "=", "runCommand", "(", "tsdb", ",", "use_data_table", ",", "args", ")", ";", "}", "finally", "{", "try", "{", "tsdb", ".", "getClient", "(", ")", ".", "shutdown", "(", ")", ".", "joinUninterruptibly", "(", ")", ";", "LOG", ".", "info", "(", "\"Gracefully shutdown the TSD\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "LOG", ".", "error", "(", "\"Unexpected exception while shutting down\"", ",", "e", ")", ";", "rc", "=", "42", ";", "}", "}", "System", ".", "exit", "(", "rc", ")", ";", "}" ]
Entry point to run the search utility @param args Command line arguments @throws Exception If something goes wrong
[ "Entry", "point", "to", "run", "the", "search", "utility" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/Search.java#L53-L86
13,440
OpenTSDB/opentsdb
src/tools/Search.java
Search.runCommand
private static int runCommand(final TSDB tsdb, final boolean use_data_table, final String[] args) throws Exception { final int nargs = args.length; if (args[0].equals("lookup")) { if (nargs < 2) { // need a query usage(null, "Not enough arguments"); return 2; } return lookup(tsdb, use_data_table, args); } else { usage(null, "Unknown sub command: " + args[0]); return 2; } }
java
private static int runCommand(final TSDB tsdb, final boolean use_data_table, final String[] args) throws Exception { final int nargs = args.length; if (args[0].equals("lookup")) { if (nargs < 2) { // need a query usage(null, "Not enough arguments"); return 2; } return lookup(tsdb, use_data_table, args); } else { usage(null, "Unknown sub command: " + args[0]); return 2; } }
[ "private", "static", "int", "runCommand", "(", "final", "TSDB", "tsdb", ",", "final", "boolean", "use_data_table", ",", "final", "String", "[", "]", "args", ")", "throws", "Exception", "{", "final", "int", "nargs", "=", "args", ".", "length", ";", "if", "(", "args", "[", "0", "]", ".", "equals", "(", "\"lookup\"", ")", ")", "{", "if", "(", "nargs", "<", "2", ")", "{", "// need a query", "usage", "(", "null", ",", "\"Not enough arguments\"", ")", ";", "return", "2", ";", "}", "return", "lookup", "(", "tsdb", ",", "use_data_table", ",", "args", ")", ";", "}", "else", "{", "usage", "(", "null", ",", "\"Unknown sub command: \"", "+", "args", "[", "0", "]", ")", ";", "return", "2", ";", "}", "}" ]
Determines the command requested of the user can calls the appropriate method. @param tsdb The TSDB to use for communication @param use_data_table Whether or not lookups should be done on the full data table @param args Arguments to parse @return An exit code
[ "Determines", "the", "command", "requested", "of", "the", "user", "can", "calls", "the", "appropriate", "method", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/Search.java#L97-L111
13,441
OpenTSDB/opentsdb
src/tsd/PutDataPointRpc.java
PutDataPointRpc.importDataPoint
protected Deferred<Object> importDataPoint(final TSDB tsdb, final String[] words) { words[0] = null; // Ditch the "put". if (words.length < 5) { // Need at least: metric timestamp value tag // ^ 5 and not 4 because words[0] is "put". throw new IllegalArgumentException("not enough arguments" + " (need least 4, got " + (words.length - 1) + ')'); } final String metric = words[1]; if (metric.length() <= 0) { throw new IllegalArgumentException("empty metric name"); } final long timestamp; if (words[2].contains(".")) { timestamp = Tags.parseLong(words[2].replace(".", "")); } else { timestamp = Tags.parseLong(words[2]); } if (timestamp <= 0) { throw new IllegalArgumentException("invalid timestamp: " + timestamp); } final String value = words[3]; if (value.length() <= 0) { throw new IllegalArgumentException("empty value"); } final HashMap<String, String> tags = new HashMap<String, String>(); for (int i = 4; i < words.length; i++) { if (!words[i].isEmpty()) { Tags.parse(tags, words[i]); } } if (Tags.looksLikeInteger(value)) { return tsdb.addPoint(metric, timestamp, Tags.parseLong(value), tags); } else if (Tags.fitsInFloat(value)) { // floating point value return tsdb.addPoint(metric, timestamp, Float.parseFloat(value), tags); } else { return tsdb.addPoint(metric, timestamp, Double.parseDouble(value), tags); } }
java
protected Deferred<Object> importDataPoint(final TSDB tsdb, final String[] words) { words[0] = null; // Ditch the "put". if (words.length < 5) { // Need at least: metric timestamp value tag // ^ 5 and not 4 because words[0] is "put". throw new IllegalArgumentException("not enough arguments" + " (need least 4, got " + (words.length - 1) + ')'); } final String metric = words[1]; if (metric.length() <= 0) { throw new IllegalArgumentException("empty metric name"); } final long timestamp; if (words[2].contains(".")) { timestamp = Tags.parseLong(words[2].replace(".", "")); } else { timestamp = Tags.parseLong(words[2]); } if (timestamp <= 0) { throw new IllegalArgumentException("invalid timestamp: " + timestamp); } final String value = words[3]; if (value.length() <= 0) { throw new IllegalArgumentException("empty value"); } final HashMap<String, String> tags = new HashMap<String, String>(); for (int i = 4; i < words.length; i++) { if (!words[i].isEmpty()) { Tags.parse(tags, words[i]); } } if (Tags.looksLikeInteger(value)) { return tsdb.addPoint(metric, timestamp, Tags.parseLong(value), tags); } else if (Tags.fitsInFloat(value)) { // floating point value return tsdb.addPoint(metric, timestamp, Float.parseFloat(value), tags); } else { return tsdb.addPoint(metric, timestamp, Double.parseDouble(value), tags); } }
[ "protected", "Deferred", "<", "Object", ">", "importDataPoint", "(", "final", "TSDB", "tsdb", ",", "final", "String", "[", "]", "words", ")", "{", "words", "[", "0", "]", "=", "null", ";", "// Ditch the \"put\".", "if", "(", "words", ".", "length", "<", "5", ")", "{", "// Need at least: metric timestamp value tag", "// ^ 5 and not 4 because words[0] is \"put\".", "throw", "new", "IllegalArgumentException", "(", "\"not enough arguments\"", "+", "\" (need least 4, got \"", "+", "(", "words", ".", "length", "-", "1", ")", "+", "'", "'", ")", ";", "}", "final", "String", "metric", "=", "words", "[", "1", "]", ";", "if", "(", "metric", ".", "length", "(", ")", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"empty metric name\"", ")", ";", "}", "final", "long", "timestamp", ";", "if", "(", "words", "[", "2", "]", ".", "contains", "(", "\".\"", ")", ")", "{", "timestamp", "=", "Tags", ".", "parseLong", "(", "words", "[", "2", "]", ".", "replace", "(", "\".\"", ",", "\"\"", ")", ")", ";", "}", "else", "{", "timestamp", "=", "Tags", ".", "parseLong", "(", "words", "[", "2", "]", ")", ";", "}", "if", "(", "timestamp", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"invalid timestamp: \"", "+", "timestamp", ")", ";", "}", "final", "String", "value", "=", "words", "[", "3", "]", ";", "if", "(", "value", ".", "length", "(", ")", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"empty value\"", ")", ";", "}", "final", "HashMap", "<", "String", ",", "String", ">", "tags", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "for", "(", "int", "i", "=", "4", ";", "i", "<", "words", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "words", "[", "i", "]", ".", "isEmpty", "(", ")", ")", "{", "Tags", ".", "parse", "(", "tags", ",", "words", "[", "i", "]", ")", ";", "}", "}", "if", "(", "Tags", ".", "looksLikeInteger", "(", "value", ")", ")", "{", "return", "tsdb", ".", "addPoint", "(", "metric", ",", "timestamp", ",", "Tags", ".", "parseLong", "(", "value", ")", ",", "tags", ")", ";", "}", "else", "if", "(", "Tags", ".", "fitsInFloat", "(", "value", ")", ")", "{", "// floating point value", "return", "tsdb", ".", "addPoint", "(", "metric", ",", "timestamp", ",", "Float", ".", "parseFloat", "(", "value", ")", ",", "tags", ")", ";", "}", "else", "{", "return", "tsdb", ".", "addPoint", "(", "metric", ",", "timestamp", ",", "Double", ".", "parseDouble", "(", "value", ")", ",", "tags", ")", ";", "}", "}" ]
Imports a single data point. @param tsdb The TSDB to import the data point into. @param words The words describing the data point to import, in the following format: {@code [metric, timestamp, value, ..tags..]} @return A deferred object that indicates the completion of the request. @throws NumberFormatException if the timestamp or value is invalid. @throws IllegalArgumentException if any other argument is invalid. @throws NoSuchUniqueName if the metric isn't registered.
[ "Imports", "a", "single", "data", "point", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/PutDataPointRpc.java#L741-L780
13,442
OpenTSDB/opentsdb
src/tsd/PutDataPointRpc.java
PutDataPointRpc.getHttpDetails
final private HashMap<String, Object> getHttpDetails(final String message, final IncomingDataPoint dp) { final HashMap<String, Object> map = new HashMap<String, Object>(); map.put("error", message); map.put("datapoint", dp); return map; }
java
final private HashMap<String, Object> getHttpDetails(final String message, final IncomingDataPoint dp) { final HashMap<String, Object> map = new HashMap<String, Object>(); map.put("error", message); map.put("datapoint", dp); return map; }
[ "final", "private", "HashMap", "<", "String", ",", "Object", ">", "getHttpDetails", "(", "final", "String", "message", ",", "final", "IncomingDataPoint", "dp", ")", "{", "final", "HashMap", "<", "String", ",", "Object", ">", "map", "=", "new", "HashMap", "<", "String", ",", "Object", ">", "(", ")", ";", "map", ".", "put", "(", "\"error\"", ",", "message", ")", ";", "map", ".", "put", "(", "\"datapoint\"", ",", "dp", ")", ";", "return", "map", ";", "}" ]
Simple helper to format an error trying to save a data point @param message The message to return to the user @param dp The datapoint that caused the error @return A hashmap with information @since 2.0
[ "Simple", "helper", "to", "format", "an", "error", "trying", "to", "save", "a", "data", "point" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/PutDataPointRpc.java#L821-L827
13,443
OpenTSDB/opentsdb
src/tsd/PutDataPointRpc.java
PutDataPointRpc.handleStorageException
void handleStorageException(final TSDB tsdb, final IncomingDataPoint dp, final Exception e) { final StorageExceptionHandler handler = tsdb.getStorageExceptionHandler(); if (handler != null) { handler.handleError(dp, e); } }
java
void handleStorageException(final TSDB tsdb, final IncomingDataPoint dp, final Exception e) { final StorageExceptionHandler handler = tsdb.getStorageExceptionHandler(); if (handler != null) { handler.handleError(dp, e); } }
[ "void", "handleStorageException", "(", "final", "TSDB", "tsdb", ",", "final", "IncomingDataPoint", "dp", ",", "final", "Exception", "e", ")", "{", "final", "StorageExceptionHandler", "handler", "=", "tsdb", ".", "getStorageExceptionHandler", "(", ")", ";", "if", "(", "handler", "!=", "null", ")", "{", "handler", ".", "handleError", "(", "dp", ",", "e", ")", ";", "}", "}" ]
Passes a data point off to the storage handler plugin if it has been configured. @param tsdb The TSDB from which to grab the SEH plugin @param dp The data point to process @param e The exception that caused this
[ "Passes", "a", "data", "point", "off", "to", "the", "storage", "handler", "plugin", "if", "it", "has", "been", "configured", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/PutDataPointRpc.java#L836-L842
13,444
OpenTSDB/opentsdb
src/tools/ArgP.java
ArgP.addOption
public void addOption(final String name, final String meta, final String help) { if (name.isEmpty()) { throw new IllegalArgumentException("empty name"); } else if (name.charAt(0) != '-') { throw new IllegalArgumentException("name must start with a `-': " + name); } else if (meta != null && meta.isEmpty()) { throw new IllegalArgumentException("empty meta"); } else if (help.isEmpty()) { throw new IllegalArgumentException("empty help"); } final String[] prev = options.put(name, new String[] { meta, help }); if (prev != null) { options.put(name, prev); // Undo the `put' above. throw new IllegalArgumentException("Option " + name + " already defined" + " in " + this); } }
java
public void addOption(final String name, final String meta, final String help) { if (name.isEmpty()) { throw new IllegalArgumentException("empty name"); } else if (name.charAt(0) != '-') { throw new IllegalArgumentException("name must start with a `-': " + name); } else if (meta != null && meta.isEmpty()) { throw new IllegalArgumentException("empty meta"); } else if (help.isEmpty()) { throw new IllegalArgumentException("empty help"); } final String[] prev = options.put(name, new String[] { meta, help }); if (prev != null) { options.put(name, prev); // Undo the `put' above. throw new IllegalArgumentException("Option " + name + " already defined" + " in " + this); } }
[ "public", "void", "addOption", "(", "final", "String", "name", ",", "final", "String", "meta", ",", "final", "String", "help", ")", "{", "if", "(", "name", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"empty name\"", ")", ";", "}", "else", "if", "(", "name", ".", "charAt", "(", "0", ")", "!=", "'", "'", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"name must start with a `-': \"", "+", "name", ")", ";", "}", "else", "if", "(", "meta", "!=", "null", "&&", "meta", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"empty meta\"", ")", ";", "}", "else", "if", "(", "help", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"empty help\"", ")", ";", "}", "final", "String", "[", "]", "prev", "=", "options", ".", "put", "(", "name", ",", "new", "String", "[", "]", "{", "meta", ",", "help", "}", ")", ";", "if", "(", "prev", "!=", "null", ")", "{", "options", ".", "put", "(", "name", ",", "prev", ")", ";", "// Undo the `put' above.", "throw", "new", "IllegalArgumentException", "(", "\"Option \"", "+", "name", "+", "\" already defined\"", "+", "\" in \"", "+", "this", ")", ";", "}", "}" ]
Registers an option in this argument parser. @param name The name of the option to recognize (e.g. {@code --foo}). @param meta The meta-variable to associate with the value of the option. @param help A short description of this option. @throws IllegalArgumentException if the given name was already used. @throws IllegalArgumentException if the name doesn't start with a dash. @throws IllegalArgumentException if any of the given strings is empty.
[ "Registers", "an", "option", "in", "this", "argument", "parser", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ArgP.java#L74-L92
13,445
OpenTSDB/opentsdb
src/tools/ArgP.java
ArgP.parse
public String[] parse(final String[] args) { parsed = new HashMap<String, String>(options.size()); ArrayList<String> unparsed = null; for (int i = 0; i < args.length; i++) { final String arg = args[i]; String[] opt = options.get(arg); if (opt != null) { // Perfect match: got --foo if (opt[0] != null) { // This option requires an argument. if (++i < args.length) { parsed.put(arg, args[i]); } else { throw new IllegalArgumentException("Missing argument for " + arg); } } else { parsed.put(arg, null); } continue; } // Is it a --foo=blah? final int equal = arg.indexOf('=', 1); if (equal > 0) { // Looks like so. final String name = arg.substring(0, equal); opt = options.get(name); if (opt != null) { parsed.put(name, arg.substring(equal + 1, arg.length())); continue; } } // Not a flag. if (unparsed == null) { unparsed = new ArrayList<String>(args.length - i); } if (!arg.isEmpty() && arg.charAt(0) == '-') { if (arg.length() == 2 && arg.charAt(1) == '-') { // `--' for (i++; i < args.length; i++) { unparsed.add(args[i]); } break; } throw new IllegalArgumentException("Unrecognized option " + arg); } unparsed.add(arg); } if (unparsed != null) { return unparsed.toArray(new String[unparsed.size()]); } else { return new String[0]; } }
java
public String[] parse(final String[] args) { parsed = new HashMap<String, String>(options.size()); ArrayList<String> unparsed = null; for (int i = 0; i < args.length; i++) { final String arg = args[i]; String[] opt = options.get(arg); if (opt != null) { // Perfect match: got --foo if (opt[0] != null) { // This option requires an argument. if (++i < args.length) { parsed.put(arg, args[i]); } else { throw new IllegalArgumentException("Missing argument for " + arg); } } else { parsed.put(arg, null); } continue; } // Is it a --foo=blah? final int equal = arg.indexOf('=', 1); if (equal > 0) { // Looks like so. final String name = arg.substring(0, equal); opt = options.get(name); if (opt != null) { parsed.put(name, arg.substring(equal + 1, arg.length())); continue; } } // Not a flag. if (unparsed == null) { unparsed = new ArrayList<String>(args.length - i); } if (!arg.isEmpty() && arg.charAt(0) == '-') { if (arg.length() == 2 && arg.charAt(1) == '-') { // `--' for (i++; i < args.length; i++) { unparsed.add(args[i]); } break; } throw new IllegalArgumentException("Unrecognized option " + arg); } unparsed.add(arg); } if (unparsed != null) { return unparsed.toArray(new String[unparsed.size()]); } else { return new String[0]; } }
[ "public", "String", "[", "]", "parse", "(", "final", "String", "[", "]", "args", ")", "{", "parsed", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", "options", ".", "size", "(", ")", ")", ";", "ArrayList", "<", "String", ">", "unparsed", "=", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "final", "String", "arg", "=", "args", "[", "i", "]", ";", "String", "[", "]", "opt", "=", "options", ".", "get", "(", "arg", ")", ";", "if", "(", "opt", "!=", "null", ")", "{", "// Perfect match: got --foo", "if", "(", "opt", "[", "0", "]", "!=", "null", ")", "{", "// This option requires an argument.", "if", "(", "++", "i", "<", "args", ".", "length", ")", "{", "parsed", ".", "put", "(", "arg", ",", "args", "[", "i", "]", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Missing argument for \"", "+", "arg", ")", ";", "}", "}", "else", "{", "parsed", ".", "put", "(", "arg", ",", "null", ")", ";", "}", "continue", ";", "}", "// Is it a --foo=blah?", "final", "int", "equal", "=", "arg", ".", "indexOf", "(", "'", "'", ",", "1", ")", ";", "if", "(", "equal", ">", "0", ")", "{", "// Looks like so.", "final", "String", "name", "=", "arg", ".", "substring", "(", "0", ",", "equal", ")", ";", "opt", "=", "options", ".", "get", "(", "name", ")", ";", "if", "(", "opt", "!=", "null", ")", "{", "parsed", ".", "put", "(", "name", ",", "arg", ".", "substring", "(", "equal", "+", "1", ",", "arg", ".", "length", "(", ")", ")", ")", ";", "continue", ";", "}", "}", "// Not a flag.", "if", "(", "unparsed", "==", "null", ")", "{", "unparsed", "=", "new", "ArrayList", "<", "String", ">", "(", "args", ".", "length", "-", "i", ")", ";", "}", "if", "(", "!", "arg", ".", "isEmpty", "(", ")", "&&", "arg", ".", "charAt", "(", "0", ")", "==", "'", "'", ")", "{", "if", "(", "arg", ".", "length", "(", ")", "==", "2", "&&", "arg", ".", "charAt", "(", "1", ")", "==", "'", "'", ")", "{", "// `--'", "for", "(", "i", "++", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "unparsed", ".", "add", "(", "args", "[", "i", "]", ")", ";", "}", "break", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"Unrecognized option \"", "+", "arg", ")", ";", "}", "unparsed", ".", "add", "(", "arg", ")", ";", "}", "if", "(", "unparsed", "!=", "null", ")", "{", "return", "unparsed", ".", "toArray", "(", "new", "String", "[", "unparsed", ".", "size", "(", ")", "]", ")", ";", "}", "else", "{", "return", "new", "String", "[", "0", "]", ";", "}", "}" ]
Parses the command line given in argument. @return The remaining words that weren't options (i.e. that didn't start with a dash). @throws IllegalArgumentException if the given command line wasn't valid.
[ "Parses", "the", "command", "line", "given", "in", "argument", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ArgP.java#L123-L171
13,446
OpenTSDB/opentsdb
src/tools/ArgP.java
ArgP.get
public String get(final String name, final String defaultv) { final String value = get(name); return value == null ? defaultv : value; }
java
public String get(final String name, final String defaultv) { final String value = get(name); return value == null ? defaultv : value; }
[ "public", "String", "get", "(", "final", "String", "name", ",", "final", "String", "defaultv", ")", "{", "final", "String", "value", "=", "get", "(", "name", ")", ";", "return", "value", "==", "null", "?", "defaultv", ":", "value", ";", "}" ]
Returns the value of the given option, or a default value. @param name The name of the option to recognize (e.g. {@code --foo}). @param defaultv The default value to return if the option wasn't given. @throws IllegalArgumentException if this option wasn't registered with {@link #addOption}. @throws IllegalStateException if {@link #parse} wasn't called.
[ "Returns", "the", "value", "of", "the", "given", "option", "or", "a", "default", "value", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ArgP.java#L199-L202
13,447
OpenTSDB/opentsdb
src/tools/ArgP.java
ArgP.has
public boolean has(final String name) { if (!options.containsKey(name)) { throw new IllegalArgumentException("Unknown option " + name); } else if (parsed == null) { throw new IllegalStateException("parse() wasn't called"); } return parsed.containsKey(name); }
java
public boolean has(final String name) { if (!options.containsKey(name)) { throw new IllegalArgumentException("Unknown option " + name); } else if (parsed == null) { throw new IllegalStateException("parse() wasn't called"); } return parsed.containsKey(name); }
[ "public", "boolean", "has", "(", "final", "String", "name", ")", "{", "if", "(", "!", "options", ".", "containsKey", "(", "name", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unknown option \"", "+", "name", ")", ";", "}", "else", "if", "(", "parsed", "==", "null", ")", "{", "throw", "new", "IllegalStateException", "(", "\"parse() wasn't called\"", ")", ";", "}", "return", "parsed", ".", "containsKey", "(", "name", ")", ";", "}" ]
Returns whether or not the given option was given. @param name The name of the option to recognize (e.g. {@code --foo}). @throws IllegalArgumentException if this option wasn't registered with {@link #addOption}. @throws IllegalStateException if {@link #parse} wasn't called.
[ "Returns", "whether", "or", "not", "the", "given", "option", "was", "given", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ArgP.java#L211-L218
13,448
OpenTSDB/opentsdb
src/tools/ArgP.java
ArgP.addUsageTo
public void addUsageTo(final StringBuilder buf) { final ArrayList<String> names = new ArrayList<String>(options.keySet()); Collections.sort(names); int max_length = 0; for (final String name : names) { final String[] opt = options.get(name); final int length = name.length() + (opt[0] == null ? 0 : opt[0].length() + 1); if (length > max_length) { max_length = length; } } for (final String name : names) { final String[] opt = options.get(name); int length = name.length(); buf.append(" ").append(name); if (opt[0] != null) { length += opt[0].length() + 1; buf.append('=').append(opt[0]); } for (int i = length; i <= max_length; i++) { buf.append(' '); } buf.append(opt[1]).append('\n'); } }
java
public void addUsageTo(final StringBuilder buf) { final ArrayList<String> names = new ArrayList<String>(options.keySet()); Collections.sort(names); int max_length = 0; for (final String name : names) { final String[] opt = options.get(name); final int length = name.length() + (opt[0] == null ? 0 : opt[0].length() + 1); if (length > max_length) { max_length = length; } } for (final String name : names) { final String[] opt = options.get(name); int length = name.length(); buf.append(" ").append(name); if (opt[0] != null) { length += opt[0].length() + 1; buf.append('=').append(opt[0]); } for (int i = length; i <= max_length; i++) { buf.append(' '); } buf.append(opt[1]).append('\n'); } }
[ "public", "void", "addUsageTo", "(", "final", "StringBuilder", "buf", ")", "{", "final", "ArrayList", "<", "String", ">", "names", "=", "new", "ArrayList", "<", "String", ">", "(", "options", ".", "keySet", "(", ")", ")", ";", "Collections", ".", "sort", "(", "names", ")", ";", "int", "max_length", "=", "0", ";", "for", "(", "final", "String", "name", ":", "names", ")", "{", "final", "String", "[", "]", "opt", "=", "options", ".", "get", "(", "name", ")", ";", "final", "int", "length", "=", "name", ".", "length", "(", ")", "+", "(", "opt", "[", "0", "]", "==", "null", "?", "0", ":", "opt", "[", "0", "]", ".", "length", "(", ")", "+", "1", ")", ";", "if", "(", "length", ">", "max_length", ")", "{", "max_length", "=", "length", ";", "}", "}", "for", "(", "final", "String", "name", ":", "names", ")", "{", "final", "String", "[", "]", "opt", "=", "options", ".", "get", "(", "name", ")", ";", "int", "length", "=", "name", ".", "length", "(", ")", ";", "buf", ".", "append", "(", "\" \"", ")", ".", "append", "(", "name", ")", ";", "if", "(", "opt", "[", "0", "]", "!=", "null", ")", "{", "length", "+=", "opt", "[", "0", "]", ".", "length", "(", ")", "+", "1", ";", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "opt", "[", "0", "]", ")", ";", "}", "for", "(", "int", "i", "=", "length", ";", "i", "<=", "max_length", ";", "i", "++", ")", "{", "buf", ".", "append", "(", "'", "'", ")", ";", "}", "buf", ".", "append", "(", "opt", "[", "1", "]", ")", ".", "append", "(", "'", "'", ")", ";", "}", "}" ]
Appends the usage to the given buffer. @param buf The buffer to write to.
[ "Appends", "the", "usage", "to", "the", "given", "buffer", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ArgP.java#L224-L249
13,449
OpenTSDB/opentsdb
src/tools/ArgP.java
ArgP.usage
public String usage() { final StringBuilder buf = new StringBuilder(16 * options.size()); addUsageTo(buf); return buf.toString(); }
java
public String usage() { final StringBuilder buf = new StringBuilder(16 * options.size()); addUsageTo(buf); return buf.toString(); }
[ "public", "String", "usage", "(", ")", "{", "final", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "16", "*", "options", ".", "size", "(", ")", ")", ";", "addUsageTo", "(", "buf", ")", ";", "return", "buf", ".", "toString", "(", ")", ";", "}" ]
Returns a usage string.
[ "Returns", "a", "usage", "string", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ArgP.java#L259-L263
13,450
OpenTSDB/opentsdb
src/tools/TextImporter.java
TextImporter.open
private static BufferedReader open(final String path) throws IOException { if (path.equals("-")) { return new BufferedReader(new InputStreamReader(System.in)); } InputStream is = new FileInputStream(path); if (path.endsWith(".gz")) { is = new GZIPInputStream(is); } // I <3 Java's IO library. return new BufferedReader(new InputStreamReader(is)); }
java
private static BufferedReader open(final String path) throws IOException { if (path.equals("-")) { return new BufferedReader(new InputStreamReader(System.in)); } InputStream is = new FileInputStream(path); if (path.endsWith(".gz")) { is = new GZIPInputStream(is); } // I <3 Java's IO library. return new BufferedReader(new InputStreamReader(is)); }
[ "private", "static", "BufferedReader", "open", "(", "final", "String", "path", ")", "throws", "IOException", "{", "if", "(", "path", ".", "equals", "(", "\"-\"", ")", ")", "{", "return", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "System", ".", "in", ")", ")", ";", "}", "InputStream", "is", "=", "new", "FileInputStream", "(", "path", ")", ";", "if", "(", "path", ".", "endsWith", "(", "\".gz\"", ")", ")", "{", "is", "=", "new", "GZIPInputStream", "(", "is", ")", ";", "}", "// I <3 Java's IO library.", "return", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "is", ")", ")", ";", "}" ]
Opens a file for reading, handling gzipped files. @param path The file to open. @return A buffered reader to read the file, decompressing it if needed. @throws IOException when shit happens.
[ "Opens", "a", "file", "for", "reading", "handling", "gzipped", "files", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/TextImporter.java#L261-L272
13,451
OpenTSDB/opentsdb
src/query/pojo/Expression.java
Expression.validate
public void validate() { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("missing or empty id"); } Query.validateId(id); if (expr == null || expr.isEmpty()) { throw new IllegalArgumentException("missing or empty expr"); } // parse it just to make sure we're happy and extract the variable names. // Will throw JexlException parsed_expression = ExpressionIterator.JEXL_ENGINE.createScript(expr); variables = new HashSet<String>(); for (final List<String> exp_list : ExpressionIterator.JEXL_ENGINE.getVariables(parsed_expression)) { for (final String variable : exp_list) { variables.add(variable); } } // others are optional if (join == null) { join = Join.Builder().setOperator(SetOperator.UNION).build(); } }
java
public void validate() { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("missing or empty id"); } Query.validateId(id); if (expr == null || expr.isEmpty()) { throw new IllegalArgumentException("missing or empty expr"); } // parse it just to make sure we're happy and extract the variable names. // Will throw JexlException parsed_expression = ExpressionIterator.JEXL_ENGINE.createScript(expr); variables = new HashSet<String>(); for (final List<String> exp_list : ExpressionIterator.JEXL_ENGINE.getVariables(parsed_expression)) { for (final String variable : exp_list) { variables.add(variable); } } // others are optional if (join == null) { join = Join.Builder().setOperator(SetOperator.UNION).build(); } }
[ "public", "void", "validate", "(", ")", "{", "if", "(", "id", "==", "null", "||", "id", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"missing or empty id\"", ")", ";", "}", "Query", ".", "validateId", "(", "id", ")", ";", "if", "(", "expr", "==", "null", "||", "expr", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"missing or empty expr\"", ")", ";", "}", "// parse it just to make sure we're happy and extract the variable names. ", "// Will throw JexlException", "parsed_expression", "=", "ExpressionIterator", ".", "JEXL_ENGINE", ".", "createScript", "(", "expr", ")", ";", "variables", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "for", "(", "final", "List", "<", "String", ">", "exp_list", ":", "ExpressionIterator", ".", "JEXL_ENGINE", ".", "getVariables", "(", "parsed_expression", ")", ")", "{", "for", "(", "final", "String", "variable", ":", "exp_list", ")", "{", "variables", ".", "add", "(", "variable", ")", ";", "}", "}", "// others are optional", "if", "(", "join", "==", "null", ")", "{", "join", "=", "Join", ".", "Builder", "(", ")", ".", "setOperator", "(", "SetOperator", ".", "UNION", ")", ".", "build", "(", ")", ";", "}", "}" ]
Validates the expression @throws IllegalArgumentException if one or more parameters were invalid
[ "Validates", "the", "expression" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/pojo/Expression.java#L97-L122
13,452
OpenTSDB/opentsdb
src/tools/CliOptions.java
CliOptions.parse
static String[] parse(final ArgP argp, String[] args) { try { args = argp.parse(args); } catch (IllegalArgumentException e) { System.err.println("Invalid usage. " + e.getMessage()); System.exit(2); } honorVerboseFlag(argp); return args; }
java
static String[] parse(final ArgP argp, String[] args) { try { args = argp.parse(args); } catch (IllegalArgumentException e) { System.err.println("Invalid usage. " + e.getMessage()); System.exit(2); } honorVerboseFlag(argp); return args; }
[ "static", "String", "[", "]", "parse", "(", "final", "ArgP", "argp", ",", "String", "[", "]", "args", ")", "{", "try", "{", "args", "=", "argp", ".", "parse", "(", "args", ")", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"Invalid usage. \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "System", ".", "exit", "(", "2", ")", ";", "}", "honorVerboseFlag", "(", "argp", ")", ";", "return", "args", ";", "}" ]
Parse the command line arguments with the given options. @param opt,ions Options to parse in the given args. @param args Command line arguments to parse. @return The remainder of the command line or {@code null} if {@code args} were invalid and couldn't be parsed.
[ "Parse", "the", "command", "line", "arguments", "with", "the", "given", "options", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/CliOptions.java#L75-L84
13,453
OpenTSDB/opentsdb
src/tools/CliOptions.java
CliOptions.getConfig
static final Config getConfig(final ArgP argp) throws IOException { // load configuration final Config config; final String config_file = argp.get("--config", ""); if (!config_file.isEmpty()) config = new Config(config_file); else config = new Config(true); // load CLI overloads overloadConfig(argp, config); // the auto metric is recorded to a class boolean flag since it's used so // often. We have to set it manually after overriding. config.setAutoMetric(config.getBoolean("tsd.core.auto_create_metrics")); return config; }
java
static final Config getConfig(final ArgP argp) throws IOException { // load configuration final Config config; final String config_file = argp.get("--config", ""); if (!config_file.isEmpty()) config = new Config(config_file); else config = new Config(true); // load CLI overloads overloadConfig(argp, config); // the auto metric is recorded to a class boolean flag since it's used so // often. We have to set it manually after overriding. config.setAutoMetric(config.getBoolean("tsd.core.auto_create_metrics")); return config; }
[ "static", "final", "Config", "getConfig", "(", "final", "ArgP", "argp", ")", "throws", "IOException", "{", "// load configuration", "final", "Config", "config", ";", "final", "String", "config_file", "=", "argp", ".", "get", "(", "\"--config\"", ",", "\"\"", ")", ";", "if", "(", "!", "config_file", ".", "isEmpty", "(", ")", ")", "config", "=", "new", "Config", "(", "config_file", ")", ";", "else", "config", "=", "new", "Config", "(", "true", ")", ";", "// load CLI overloads", "overloadConfig", "(", "argp", ",", "config", ")", ";", "// the auto metric is recorded to a class boolean flag since it's used so", "// often. We have to set it manually after overriding.", "config", ".", "setAutoMetric", "(", "config", ".", "getBoolean", "(", "\"tsd.core.auto_create_metrics\"", ")", ")", ";", "return", "config", ";", "}" ]
Attempts to load a configuration given a file or default files and overrides with command line arguments @return A config object with user settings or defaults @throws IOException If there was an error opening any of the config files @throws FileNotFoundException If the user provided config file was not found @since 2.0
[ "Attempts", "to", "load", "a", "configuration", "given", "a", "file", "or", "default", "files", "and", "overrides", "with", "command", "line", "arguments" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/CliOptions.java#L94-L109
13,454
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.loadConfigSource
protected static void loadConfigSource(ConfigArgP config, String source) { Properties p = loadConfig(source); Config c = config.getConfig(); for(String key: p.stringPropertyNames()) { String value = p.getProperty(key); ConfigurationItem ci = config.getConfigurationItem(key); if(ci!=null) { // if we recognize the key, validate it ci.setValue(processConfigValue(value)); } c.overrideConfig(key, processConfigValue(value)); } }
java
protected static void loadConfigSource(ConfigArgP config, String source) { Properties p = loadConfig(source); Config c = config.getConfig(); for(String key: p.stringPropertyNames()) { String value = p.getProperty(key); ConfigurationItem ci = config.getConfigurationItem(key); if(ci!=null) { // if we recognize the key, validate it ci.setValue(processConfigValue(value)); } c.overrideConfig(key, processConfigValue(value)); } }
[ "protected", "static", "void", "loadConfigSource", "(", "ConfigArgP", "config", ",", "String", "source", ")", "{", "Properties", "p", "=", "loadConfig", "(", "source", ")", ";", "Config", "c", "=", "config", ".", "getConfig", "(", ")", ";", "for", "(", "String", "key", ":", "p", ".", "stringPropertyNames", "(", ")", ")", "{", "String", "value", "=", "p", ".", "getProperty", "(", "key", ")", ";", "ConfigurationItem", "ci", "=", "config", ".", "getConfigurationItem", "(", "key", ")", ";", "if", "(", "ci", "!=", "null", ")", "{", "// if we recognize the key, validate it", "ci", ".", "setValue", "(", "processConfigValue", "(", "value", ")", ")", ";", "}", "c", ".", "overrideConfig", "(", "key", ",", "processConfigValue", "(", "value", ")", ")", ";", "}", "}" ]
Applies the properties from the named source to the main configuration @param config the main configuration to apply to @param source the name of the source to apply properties from
[ "Applies", "the", "properties", "from", "the", "named", "source", "to", "the", "main", "configuration" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L207-L218
13,455
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.loadConfig
protected static Properties loadConfig(String name) { try { URL url = new URL(name); return loadConfig(url); } catch (Exception ex) { return loadConfig(new File(name)); } }
java
protected static Properties loadConfig(String name) { try { URL url = new URL(name); return loadConfig(url); } catch (Exception ex) { return loadConfig(new File(name)); } }
[ "protected", "static", "Properties", "loadConfig", "(", "String", "name", ")", "{", "try", "{", "URL", "url", "=", "new", "URL", "(", "name", ")", ";", "return", "loadConfig", "(", "url", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "return", "loadConfig", "(", "new", "File", "(", "name", ")", ")", ";", "}", "}" ]
Loads properties from a file or url with the passed name @param name The name of the file or URL @return the loaded properties
[ "Loads", "properties", "from", "a", "file", "or", "url", "with", "the", "passed", "name" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L225-L232
13,456
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.loadConfig
protected static Properties loadConfig(String source, InputStream is) { try { Properties p = new Properties(); p.load(is); // trim the value as it may have trailing white-space Set<String> keys = p.stringPropertyNames(); for(String key: keys) { p.setProperty(key, p.getProperty(key).trim()); } return p; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new IllegalArgumentException("Failed to load configuration from [" + source + "]"); } }
java
protected static Properties loadConfig(String source, InputStream is) { try { Properties p = new Properties(); p.load(is); // trim the value as it may have trailing white-space Set<String> keys = p.stringPropertyNames(); for(String key: keys) { p.setProperty(key, p.getProperty(key).trim()); } return p; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new IllegalArgumentException("Failed to load configuration from [" + source + "]"); } }
[ "protected", "static", "Properties", "loadConfig", "(", "String", "source", ",", "InputStream", "is", ")", "{", "try", "{", "Properties", "p", "=", "new", "Properties", "(", ")", ";", "p", ".", "load", "(", "is", ")", ";", "// trim the value as it may have trailing white-space", "Set", "<", "String", ">", "keys", "=", "p", ".", "stringPropertyNames", "(", ")", ";", "for", "(", "String", "key", ":", "keys", ")", "{", "p", ".", "setProperty", "(", "key", ",", "p", ".", "getProperty", "(", "key", ")", ".", "trim", "(", ")", ")", ";", "}", "return", "p", ";", "}", "catch", "(", "IllegalArgumentException", "iae", ")", "{", "throw", "iae", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Failed to load configuration from [\"", "+", "source", "+", "\"]\"", ")", ";", "}", "}" ]
Loads properties from the passed input stream @param source The name of the source the properties are being loaded from @param is The input stream to load from @return the loaded properties
[ "Loads", "properties", "from", "the", "passed", "input", "stream" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L240-L255
13,457
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.loadConfig
protected static Properties loadConfig(File file) { InputStream is = null; try { is = new FileInputStream(file); return loadConfig(file.getAbsolutePath(), is); } catch (Exception ex) { throw new IllegalArgumentException("Failed to load configuration from [" + file.getAbsolutePath() + "]"); }finally { if(is!=null) try { is.close(); } catch (Exception ex) { /* No Op */ } } }
java
protected static Properties loadConfig(File file) { InputStream is = null; try { is = new FileInputStream(file); return loadConfig(file.getAbsolutePath(), is); } catch (Exception ex) { throw new IllegalArgumentException("Failed to load configuration from [" + file.getAbsolutePath() + "]"); }finally { if(is!=null) try { is.close(); } catch (Exception ex) { /* No Op */ } } }
[ "protected", "static", "Properties", "loadConfig", "(", "File", "file", ")", "{", "InputStream", "is", "=", "null", ";", "try", "{", "is", "=", "new", "FileInputStream", "(", "file", ")", ";", "return", "loadConfig", "(", "file", ".", "getAbsolutePath", "(", ")", ",", "is", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Failed to load configuration from [\"", "+", "file", ".", "getAbsolutePath", "(", ")", "+", "\"]\"", ")", ";", "}", "finally", "{", "if", "(", "is", "!=", "null", ")", "try", "{", "is", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "/* No Op */", "}", "}", "}" ]
Loads properties from the passed file @param file The file to load from @return the loaded properties
[ "Loads", "properties", "from", "the", "passed", "file" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L262-L272
13,458
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.applyArgs
public String[] applyArgs(String[] clargs) { LOG.debug("Applying Command Line Args {}", Arrays.toString(clargs)); final List<String> nonFlagArgs = new ArrayList<String>(Arrays.asList(clargs)); extractAndApplyFlags(nonFlagArgs); String[] args = nonFlagArgs.toArray(new String[0]); String[] nonArgs = argp.parse(args); LOG.debug("Applying Command Line ArgP {}", argp); LOG.debug("configItemsByCl Keys: [{}]", configItemsByCl.toString()); for(Map.Entry<String, String> entry: argp.getParsed().entrySet()) { String key = entry.getKey(), value = entry.getValue(); ConfigurationItem citem = getConfigurationItemByClOpt(key); LOG.debug("Loaded CI for command line option [{}]: Found:{}", key, citem!=null); if("BOOL".equals(citem.getMeta())) { citem.setValue(value!=null ? value : "true"); } else { if(value!=null) { citem.setValue(processConfigValue(value)); } } // log("CL Override [%s] --> [%s]", citem.getKey(), citem.getValue()); config.overrideConfig(citem.getKey(), citem.getValue()); } return nonArgs; }
java
public String[] applyArgs(String[] clargs) { LOG.debug("Applying Command Line Args {}", Arrays.toString(clargs)); final List<String> nonFlagArgs = new ArrayList<String>(Arrays.asList(clargs)); extractAndApplyFlags(nonFlagArgs); String[] args = nonFlagArgs.toArray(new String[0]); String[] nonArgs = argp.parse(args); LOG.debug("Applying Command Line ArgP {}", argp); LOG.debug("configItemsByCl Keys: [{}]", configItemsByCl.toString()); for(Map.Entry<String, String> entry: argp.getParsed().entrySet()) { String key = entry.getKey(), value = entry.getValue(); ConfigurationItem citem = getConfigurationItemByClOpt(key); LOG.debug("Loaded CI for command line option [{}]: Found:{}", key, citem!=null); if("BOOL".equals(citem.getMeta())) { citem.setValue(value!=null ? value : "true"); } else { if(value!=null) { citem.setValue(processConfigValue(value)); } } // log("CL Override [%s] --> [%s]", citem.getKey(), citem.getValue()); config.overrideConfig(citem.getKey(), citem.getValue()); } return nonArgs; }
[ "public", "String", "[", "]", "applyArgs", "(", "String", "[", "]", "clargs", ")", "{", "LOG", ".", "debug", "(", "\"Applying Command Line Args {}\"", ",", "Arrays", ".", "toString", "(", "clargs", ")", ")", ";", "final", "List", "<", "String", ">", "nonFlagArgs", "=", "new", "ArrayList", "<", "String", ">", "(", "Arrays", ".", "asList", "(", "clargs", ")", ")", ";", "extractAndApplyFlags", "(", "nonFlagArgs", ")", ";", "String", "[", "]", "args", "=", "nonFlagArgs", ".", "toArray", "(", "new", "String", "[", "0", "]", ")", ";", "String", "[", "]", "nonArgs", "=", "argp", ".", "parse", "(", "args", ")", ";", "LOG", ".", "debug", "(", "\"Applying Command Line ArgP {}\"", ",", "argp", ")", ";", "LOG", ".", "debug", "(", "\"configItemsByCl Keys: [{}]\"", ",", "configItemsByCl", ".", "toString", "(", ")", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "String", ">", "entry", ":", "argp", ".", "getParsed", "(", ")", ".", "entrySet", "(", ")", ")", "{", "String", "key", "=", "entry", ".", "getKey", "(", ")", ",", "value", "=", "entry", ".", "getValue", "(", ")", ";", "ConfigurationItem", "citem", "=", "getConfigurationItemByClOpt", "(", "key", ")", ";", "LOG", ".", "debug", "(", "\"Loaded CI for command line option [{}]: Found:{}\"", ",", "key", ",", "citem", "!=", "null", ")", ";", "if", "(", "\"BOOL\"", ".", "equals", "(", "citem", ".", "getMeta", "(", ")", ")", ")", "{", "citem", ".", "setValue", "(", "value", "!=", "null", "?", "value", ":", "\"true\"", ")", ";", "}", "else", "{", "if", "(", "value", "!=", "null", ")", "{", "citem", ".", "setValue", "(", "processConfigValue", "(", "value", ")", ")", ";", "}", "}", "// log(\"CL Override [%s] --> [%s]\", citem.getKey(), citem.getValue());", "config", ".", "overrideConfig", "(", "citem", ".", "getKey", "(", ")", ",", "citem", ".", "getValue", "(", ")", ")", ";", "}", "return", "nonArgs", ";", "}" ]
Parses the command line arguments, and where the options are recognized config items, the value is validated, then applied to the config @param clargs The command line arguments @return The un-applied command line arguments
[ "Parses", "the", "command", "line", "arguments", "and", "where", "the", "options", "are", "recognized", "config", "items", "the", "value", "is", "validated", "then", "applied", "to", "the", "config" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L320-L344
13,459
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.getDefaultUsage
public String getDefaultUsage(String...msgs) { StringBuilder b = new StringBuilder("\n"); for(String msg: msgs) { b.append(msg).append("\n"); } b.append(dargp.usage()); return b.toString(); }
java
public String getDefaultUsage(String...msgs) { StringBuilder b = new StringBuilder("\n"); for(String msg: msgs) { b.append(msg).append("\n"); } b.append(dargp.usage()); return b.toString(); }
[ "public", "String", "getDefaultUsage", "(", "String", "...", "msgs", ")", "{", "StringBuilder", "b", "=", "new", "StringBuilder", "(", "\"\\n\"", ")", ";", "for", "(", "String", "msg", ":", "msgs", ")", "{", "b", ".", "append", "(", "msg", ")", ".", "append", "(", "\"\\n\"", ")", ";", "}", "b", ".", "append", "(", "dargp", ".", "usage", "(", ")", ")", ";", "return", "b", ".", "toString", "(", ")", ";", "}" ]
Returns a default usage banner with optional prefixed messages, one per line. @param msgs The optional message @return the formatted usage banner
[ "Returns", "a", "default", "usage", "banner", "with", "optional", "prefixed", "messages", "one", "per", "line", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L408-L415
13,460
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.getExtendedUsage
public String getExtendedUsage(String...msgs) { StringBuilder b = new StringBuilder("\n"); for(String msg: msgs) { b.append(msg).append("\n"); } b.append(argp.usage()); return b.toString(); }
java
public String getExtendedUsage(String...msgs) { StringBuilder b = new StringBuilder("\n"); for(String msg: msgs) { b.append(msg).append("\n"); } b.append(argp.usage()); return b.toString(); }
[ "public", "String", "getExtendedUsage", "(", "String", "...", "msgs", ")", "{", "StringBuilder", "b", "=", "new", "StringBuilder", "(", "\"\\n\"", ")", ";", "for", "(", "String", "msg", ":", "msgs", ")", "{", "b", ".", "append", "(", "msg", ")", ".", "append", "(", "\"\\n\"", ")", ";", "}", "b", ".", "append", "(", "argp", ".", "usage", "(", ")", ")", ";", "return", "b", ".", "toString", "(", ")", ";", "}" ]
Returns an extended usage banner with optional prefixed messages, one per line. @param msgs The optional message @return the formatted usage banner
[ "Returns", "an", "extended", "usage", "banner", "with", "optional", "prefixed", "messages", "one", "per", "line", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L422-L429
13,461
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.log
public static void log(String format, Object...args) { System.out.println(String.format(format, args)); }
java
public static void log(String format, Object...args) { System.out.println(String.format(format, args)); }
[ "public", "static", "void", "log", "(", "String", "format", ",", "Object", "...", "args", ")", "{", "System", ".", "out", ".", "println", "(", "String", ".", "format", "(", "format", ",", "args", ")", ")", ";", "}" ]
System out logger @param format The message format @param args The message arg tokens
[ "System", "out", "logger" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L437-L439
13,462
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.processConfigValue
public static String processConfigValue(CharSequence text) { final String pv = evaluate(tokenReplaceSysProps(text)); return (pv==null || pv.trim().isEmpty()) ? null : pv; }
java
public static String processConfigValue(CharSequence text) { final String pv = evaluate(tokenReplaceSysProps(text)); return (pv==null || pv.trim().isEmpty()) ? null : pv; }
[ "public", "static", "String", "processConfigValue", "(", "CharSequence", "text", ")", "{", "final", "String", "pv", "=", "evaluate", "(", "tokenReplaceSysProps", "(", "text", ")", ")", ";", "return", "(", "pv", "==", "null", "||", "pv", ".", "trim", "(", ")", ".", "isEmpty", "(", ")", ")", "?", "null", ":", "pv", ";", "}" ]
Performs sys-prop and js evals on the passed value @param text The value to process @return the processed value
[ "Performs", "sys", "-", "prop", "and", "js", "evals", "on", "the", "passed", "value" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L446-L449
13,463
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.tokenReplaceSysProps
public static String tokenReplaceSysProps(CharSequence text) { if(text==null) return null; Matcher m = SYS_PROP_PATTERN.matcher(text); StringBuffer ret = new StringBuffer(); while(m.find()) { String replacement = decodeToken(m.group(1), m.group(2)==null ? "<null>" : m.group(2)); if(replacement==null) { throw new IllegalArgumentException("Failed to fill in SystemProperties for expression with no default [" + text + "]"); } if(IS_WINDOWS) { replacement = replacement.replace(File.separatorChar , '/'); } m.appendReplacement(ret, replacement); } m.appendTail(ret); return ret.toString(); }
java
public static String tokenReplaceSysProps(CharSequence text) { if(text==null) return null; Matcher m = SYS_PROP_PATTERN.matcher(text); StringBuffer ret = new StringBuffer(); while(m.find()) { String replacement = decodeToken(m.group(1), m.group(2)==null ? "<null>" : m.group(2)); if(replacement==null) { throw new IllegalArgumentException("Failed to fill in SystemProperties for expression with no default [" + text + "]"); } if(IS_WINDOWS) { replacement = replacement.replace(File.separatorChar , '/'); } m.appendReplacement(ret, replacement); } m.appendTail(ret); return ret.toString(); }
[ "public", "static", "String", "tokenReplaceSysProps", "(", "CharSequence", "text", ")", "{", "if", "(", "text", "==", "null", ")", "return", "null", ";", "Matcher", "m", "=", "SYS_PROP_PATTERN", ".", "matcher", "(", "text", ")", ";", "StringBuffer", "ret", "=", "new", "StringBuffer", "(", ")", ";", "while", "(", "m", ".", "find", "(", ")", ")", "{", "String", "replacement", "=", "decodeToken", "(", "m", ".", "group", "(", "1", ")", ",", "m", ".", "group", "(", "2", ")", "==", "null", "?", "\"<null>\"", ":", "m", ".", "group", "(", "2", ")", ")", ";", "if", "(", "replacement", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Failed to fill in SystemProperties for expression with no default [\"", "+", "text", "+", "\"]\"", ")", ";", "}", "if", "(", "IS_WINDOWS", ")", "{", "replacement", "=", "replacement", ".", "replace", "(", "File", ".", "separatorChar", ",", "'", "'", ")", ";", "}", "m", ".", "appendReplacement", "(", "ret", ",", "replacement", ")", ";", "}", "m", ".", "appendTail", "(", "ret", ")", ";", "return", "ret", ".", "toString", "(", ")", ";", "}" ]
Replaces all matched tokens with the matching system property value or a configured default @param text The text to process @return The substituted string
[ "Replaces", "all", "matched", "tokens", "with", "the", "matching", "system", "property", "value", "or", "a", "configured", "default" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L456-L472
13,464
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.evaluate
public static String evaluate(CharSequence text) { if(text==null) return null; Matcher m = JS_PATTERN.matcher(text); StringBuffer ret = new StringBuffer(); final boolean isNas = scriptEngine.getFactory().getEngineName().toLowerCase().contains("nashorn"); while(m.find()) { String source = (isNas ? "load(\"nashorn:mozilla_compat.js\");\nimportPackage(java.lang); " : "\nimportPackage(java.lang); " ) + m.group(1); try { Object obj = scriptEngine.eval(source, bindings); if(obj!=null) { //log("Evaled [%s] --> [%s]", source, obj); m.appendReplacement(ret, obj.toString()); } else { m.appendReplacement(ret, ""); } } catch (Exception ex) { ex.printStackTrace(System.err); throw new IllegalArgumentException("Failed to evaluate expression [" + text + "]"); } } m.appendTail(ret); return ret.toString(); }
java
public static String evaluate(CharSequence text) { if(text==null) return null; Matcher m = JS_PATTERN.matcher(text); StringBuffer ret = new StringBuffer(); final boolean isNas = scriptEngine.getFactory().getEngineName().toLowerCase().contains("nashorn"); while(m.find()) { String source = (isNas ? "load(\"nashorn:mozilla_compat.js\");\nimportPackage(java.lang); " : "\nimportPackage(java.lang); " ) + m.group(1); try { Object obj = scriptEngine.eval(source, bindings); if(obj!=null) { //log("Evaled [%s] --> [%s]", source, obj); m.appendReplacement(ret, obj.toString()); } else { m.appendReplacement(ret, ""); } } catch (Exception ex) { ex.printStackTrace(System.err); throw new IllegalArgumentException("Failed to evaluate expression [" + text + "]"); } } m.appendTail(ret); return ret.toString(); }
[ "public", "static", "String", "evaluate", "(", "CharSequence", "text", ")", "{", "if", "(", "text", "==", "null", ")", "return", "null", ";", "Matcher", "m", "=", "JS_PATTERN", ".", "matcher", "(", "text", ")", ";", "StringBuffer", "ret", "=", "new", "StringBuffer", "(", ")", ";", "final", "boolean", "isNas", "=", "scriptEngine", ".", "getFactory", "(", ")", ".", "getEngineName", "(", ")", ".", "toLowerCase", "(", ")", ".", "contains", "(", "\"nashorn\"", ")", ";", "while", "(", "m", ".", "find", "(", ")", ")", "{", "String", "source", "=", "(", "isNas", "?", "\"load(\\\"nashorn:mozilla_compat.js\\\");\\nimportPackage(java.lang); \"", ":", "\"\\nimportPackage(java.lang); \"", ")", "+", "m", ".", "group", "(", "1", ")", ";", "try", "{", "Object", "obj", "=", "scriptEngine", ".", "eval", "(", "source", ",", "bindings", ")", ";", "if", "(", "obj", "!=", "null", ")", "{", "//log(\"Evaled [%s] --> [%s]\", source, obj);", "m", ".", "appendReplacement", "(", "ret", ",", "obj", ".", "toString", "(", ")", ")", ";", "}", "else", "{", "m", ".", "appendReplacement", "(", "ret", ",", "\"\"", ")", ";", "}", "}", "catch", "(", "Exception", "ex", ")", "{", "ex", ".", "printStackTrace", "(", "System", ".", "err", ")", ";", "throw", "new", "IllegalArgumentException", "(", "\"Failed to evaluate expression [\"", "+", "text", "+", "\"]\"", ")", ";", "}", "}", "m", ".", "appendTail", "(", "ret", ")", ";", "return", "ret", ".", "toString", "(", ")", ";", "}" ]
Evaluates JS expressions defines as configuration values @param text The value of a configuration item to evaluate for JS expressions @return The passed value with any embedded JS expressions evaluated and replaced
[ "Evaluates", "JS", "expressions", "defines", "as", "configuration", "values" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L479-L506
13,465
OpenTSDB/opentsdb
src/tools/ConfigArgP.java
ConfigArgP.hasNonOption
public boolean hasNonOption(String nonOptionKey) { if(nonOptionArgs==null || nonOptionArgs.length==0 || nonOptionKey==null || nonOptionKey.trim().isEmpty()) return false; return Arrays.binarySearch(nonOptionArgs, nonOptionKey) >= 0; }
java
public boolean hasNonOption(String nonOptionKey) { if(nonOptionArgs==null || nonOptionArgs.length==0 || nonOptionKey==null || nonOptionKey.trim().isEmpty()) return false; return Arrays.binarySearch(nonOptionArgs, nonOptionKey) >= 0; }
[ "public", "boolean", "hasNonOption", "(", "String", "nonOptionKey", ")", "{", "if", "(", "nonOptionArgs", "==", "null", "||", "nonOptionArgs", ".", "length", "==", "0", "||", "nonOptionKey", "==", "null", "||", "nonOptionKey", ".", "trim", "(", ")", ".", "isEmpty", "(", ")", ")", "return", "false", ";", "return", "Arrays", ".", "binarySearch", "(", "nonOptionArgs", ",", "nonOptionKey", ")", ">=", "0", ";", "}" ]
Determines if the passed key is contained in the non option args @param nonOptionKey The non option key to check for @return true if the passed key is present, false otherwise
[ "Determines", "if", "the", "passed", "key", "is", "contained", "in", "the", "non", "option", "args" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/ConfigArgP.java#L799-L802
13,466
OpenTSDB/opentsdb
src/tsd/SearchRpc.java
SearchRpc.parseQueryString
private final SearchQuery parseQueryString(final HttpQuery query, final SearchType type) { final SearchQuery search_query = new SearchQuery(); if (type == SearchType.LOOKUP) { final String query_string = query.getRequiredQueryStringParam("m"); search_query.setTags(new ArrayList<Pair<String, String>>()); try { search_query.setMetric(Tags.parseWithMetric(query_string, search_query.getTags())); } catch (IllegalArgumentException e) { throw new BadRequestException("Unable to parse query", e); } if (query.hasQueryStringParam("limit")) { final String limit = query.getQueryStringParam("limit"); try { search_query.setLimit(Integer.parseInt(limit)); } catch (NumberFormatException e) { throw new BadRequestException( "Unable to convert 'limit' to a valid number"); } } return search_query; } // process a regular search query search_query.setQuery(query.getRequiredQueryStringParam("query")); if (query.hasQueryStringParam("limit")) { final String limit = query.getQueryStringParam("limit"); try { search_query.setLimit(Integer.parseInt(limit)); } catch (NumberFormatException e) { throw new BadRequestException( "Unable to convert 'limit' to a valid number"); } } if (query.hasQueryStringParam("start_index")) { final String idx = query.getQueryStringParam("start_index"); try { search_query.setStartIndex(Integer.parseInt(idx)); } catch (NumberFormatException e) { throw new BadRequestException( "Unable to convert 'start_index' to a valid number"); } } if (query.hasQueryStringParam("use_meta")) { search_query.setUseMeta(Boolean.parseBoolean( query.getQueryStringParam("use_meta"))); } return search_query; }
java
private final SearchQuery parseQueryString(final HttpQuery query, final SearchType type) { final SearchQuery search_query = new SearchQuery(); if (type == SearchType.LOOKUP) { final String query_string = query.getRequiredQueryStringParam("m"); search_query.setTags(new ArrayList<Pair<String, String>>()); try { search_query.setMetric(Tags.parseWithMetric(query_string, search_query.getTags())); } catch (IllegalArgumentException e) { throw new BadRequestException("Unable to parse query", e); } if (query.hasQueryStringParam("limit")) { final String limit = query.getQueryStringParam("limit"); try { search_query.setLimit(Integer.parseInt(limit)); } catch (NumberFormatException e) { throw new BadRequestException( "Unable to convert 'limit' to a valid number"); } } return search_query; } // process a regular search query search_query.setQuery(query.getRequiredQueryStringParam("query")); if (query.hasQueryStringParam("limit")) { final String limit = query.getQueryStringParam("limit"); try { search_query.setLimit(Integer.parseInt(limit)); } catch (NumberFormatException e) { throw new BadRequestException( "Unable to convert 'limit' to a valid number"); } } if (query.hasQueryStringParam("start_index")) { final String idx = query.getQueryStringParam("start_index"); try { search_query.setStartIndex(Integer.parseInt(idx)); } catch (NumberFormatException e) { throw new BadRequestException( "Unable to convert 'start_index' to a valid number"); } } if (query.hasQueryStringParam("use_meta")) { search_query.setUseMeta(Boolean.parseBoolean( query.getQueryStringParam("use_meta"))); } return search_query; }
[ "private", "final", "SearchQuery", "parseQueryString", "(", "final", "HttpQuery", "query", ",", "final", "SearchType", "type", ")", "{", "final", "SearchQuery", "search_query", "=", "new", "SearchQuery", "(", ")", ";", "if", "(", "type", "==", "SearchType", ".", "LOOKUP", ")", "{", "final", "String", "query_string", "=", "query", ".", "getRequiredQueryStringParam", "(", "\"m\"", ")", ";", "search_query", ".", "setTags", "(", "new", "ArrayList", "<", "Pair", "<", "String", ",", "String", ">", ">", "(", ")", ")", ";", "try", "{", "search_query", ".", "setMetric", "(", "Tags", ".", "parseWithMetric", "(", "query_string", ",", "search_query", ".", "getTags", "(", ")", ")", ")", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "throw", "new", "BadRequestException", "(", "\"Unable to parse query\"", ",", "e", ")", ";", "}", "if", "(", "query", ".", "hasQueryStringParam", "(", "\"limit\"", ")", ")", "{", "final", "String", "limit", "=", "query", ".", "getQueryStringParam", "(", "\"limit\"", ")", ";", "try", "{", "search_query", ".", "setLimit", "(", "Integer", ".", "parseInt", "(", "limit", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "throw", "new", "BadRequestException", "(", "\"Unable to convert 'limit' to a valid number\"", ")", ";", "}", "}", "return", "search_query", ";", "}", "// process a regular search query", "search_query", ".", "setQuery", "(", "query", ".", "getRequiredQueryStringParam", "(", "\"query\"", ")", ")", ";", "if", "(", "query", ".", "hasQueryStringParam", "(", "\"limit\"", ")", ")", "{", "final", "String", "limit", "=", "query", ".", "getQueryStringParam", "(", "\"limit\"", ")", ";", "try", "{", "search_query", ".", "setLimit", "(", "Integer", ".", "parseInt", "(", "limit", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "throw", "new", "BadRequestException", "(", "\"Unable to convert 'limit' to a valid number\"", ")", ";", "}", "}", "if", "(", "query", ".", "hasQueryStringParam", "(", "\"start_index\"", ")", ")", "{", "final", "String", "idx", "=", "query", ".", "getQueryStringParam", "(", "\"start_index\"", ")", ";", "try", "{", "search_query", ".", "setStartIndex", "(", "Integer", ".", "parseInt", "(", "idx", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "throw", "new", "BadRequestException", "(", "\"Unable to convert 'start_index' to a valid number\"", ")", ";", "}", "}", "if", "(", "query", ".", "hasQueryStringParam", "(", "\"use_meta\"", ")", ")", "{", "search_query", ".", "setUseMeta", "(", "Boolean", ".", "parseBoolean", "(", "query", ".", "getQueryStringParam", "(", "\"use_meta\"", ")", ")", ")", ";", "}", "return", "search_query", ";", "}" ]
Parses required search values from the query string @param query The HTTP query to work with @param type The type of search query requested @return A parsed SearchQuery object
[ "Parses", "required", "search", "values", "from", "the", "query", "string" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/SearchRpc.java#L106-L161
13,467
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.internalError
@Override public void internalError(final Exception cause) { logError("Internal Server Error on " + request().getUri(), cause); if (this.api_version > 0) { // always default to the latest version of the error formatter since we // need to return something switch (this.api_version) { case 1: default: sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, serializer.formatErrorV1(cause)); } return; } ThrowableProxy tp = new ThrowableProxy(cause); tp.calculatePackagingData(); final String pretty_exc = ThrowableProxyUtil.asString(tp); tp = null; if (hasQueryStringParam("json")) { // 32 = 10 + some extra space as exceptions always have \t's to escape. final StringBuilder buf = new StringBuilder(32 + pretty_exc.length()); buf.append("{\"err\":\""); HttpQuery.escapeJson(pretty_exc, buf); buf.append("\"}"); sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, buf); } else { sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, makePage("Internal Server Error", "Houston, we have a problem", "<blockquote>" + "<h1>Internal Server Error</h1>" + "Oops, sorry but your request failed due to a" + " server error.<br/><br/>" + "Please try again in 30 seconds.<pre>" + pretty_exc + "</pre></blockquote>")); } }
java
@Override public void internalError(final Exception cause) { logError("Internal Server Error on " + request().getUri(), cause); if (this.api_version > 0) { // always default to the latest version of the error formatter since we // need to return something switch (this.api_version) { case 1: default: sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, serializer.formatErrorV1(cause)); } return; } ThrowableProxy tp = new ThrowableProxy(cause); tp.calculatePackagingData(); final String pretty_exc = ThrowableProxyUtil.asString(tp); tp = null; if (hasQueryStringParam("json")) { // 32 = 10 + some extra space as exceptions always have \t's to escape. final StringBuilder buf = new StringBuilder(32 + pretty_exc.length()); buf.append("{\"err\":\""); HttpQuery.escapeJson(pretty_exc, buf); buf.append("\"}"); sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, buf); } else { sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, makePage("Internal Server Error", "Houston, we have a problem", "<blockquote>" + "<h1>Internal Server Error</h1>" + "Oops, sorry but your request failed due to a" + " server error.<br/><br/>" + "Please try again in 30 seconds.<pre>" + pretty_exc + "</pre></blockquote>")); } }
[ "@", "Override", "public", "void", "internalError", "(", "final", "Exception", "cause", ")", "{", "logError", "(", "\"Internal Server Error on \"", "+", "request", "(", ")", ".", "getUri", "(", ")", ",", "cause", ")", ";", "if", "(", "this", ".", "api_version", ">", "0", ")", "{", "// always default to the latest version of the error formatter since we", "// need to return something", "switch", "(", "this", ".", "api_version", ")", "{", "case", "1", ":", "default", ":", "sendReply", "(", "HttpResponseStatus", ".", "INTERNAL_SERVER_ERROR", ",", "serializer", ".", "formatErrorV1", "(", "cause", ")", ")", ";", "}", "return", ";", "}", "ThrowableProxy", "tp", "=", "new", "ThrowableProxy", "(", "cause", ")", ";", "tp", ".", "calculatePackagingData", "(", ")", ";", "final", "String", "pretty_exc", "=", "ThrowableProxyUtil", ".", "asString", "(", "tp", ")", ";", "tp", "=", "null", ";", "if", "(", "hasQueryStringParam", "(", "\"json\"", ")", ")", "{", "// 32 = 10 + some extra space as exceptions always have \\t's to escape.", "final", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "32", "+", "pretty_exc", ".", "length", "(", ")", ")", ";", "buf", ".", "append", "(", "\"{\\\"err\\\":\\\"\"", ")", ";", "HttpQuery", ".", "escapeJson", "(", "pretty_exc", ",", "buf", ")", ";", "buf", ".", "append", "(", "\"\\\"}\"", ")", ";", "sendReply", "(", "HttpResponseStatus", ".", "INTERNAL_SERVER_ERROR", ",", "buf", ")", ";", "}", "else", "{", "sendReply", "(", "HttpResponseStatus", ".", "INTERNAL_SERVER_ERROR", ",", "makePage", "(", "\"Internal Server Error\"", ",", "\"Houston, we have a problem\"", ",", "\"<blockquote>\"", "+", "\"<h1>Internal Server Error</h1>\"", "+", "\"Oops, sorry but your request failed due to a\"", "+", "\" server error.<br/><br/>\"", "+", "\"Please try again in 30 seconds.<pre>\"", "+", "pretty_exc", "+", "\"</pre></blockquote>\"", ")", ")", ";", "}", "}" ]
Sends a 500 error page to the client. Handles responses from deprecated API calls as well as newer, versioned API calls @param cause The unexpected exception that caused this error.
[ "Sends", "a", "500", "error", "page", "to", "the", "client", ".", "Handles", "responses", "from", "deprecated", "API", "calls", "as", "well", "as", "newer", "versioned", "API", "calls" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L348-L386
13,468
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.badRequest
@Override public void badRequest(final BadRequestException exception) { logWarn("Bad Request on " + request().getUri() + ": " + exception.getMessage()); if (this.api_version > 0) { // always default to the latest version of the error formatter since we // need to return something switch (this.api_version) { case 1: default: sendReply(exception.getStatus(), serializer.formatErrorV1(exception)); } return; } if (hasQueryStringParam("json")) { final StringBuilder buf = new StringBuilder(10 + exception.getDetails().length()); buf.append("{\"err\":\""); HttpQuery.escapeJson(exception.getMessage(), buf); buf.append("\"}"); sendReply(HttpResponseStatus.BAD_REQUEST, buf); } else { sendReply(HttpResponseStatus.BAD_REQUEST, makePage("Bad Request", "Looks like it's your fault this time", "<blockquote>" + "<h1>Bad Request</h1>" + "Sorry but your request was rejected as being" + " invalid.<br/><br/>" + "The reason provided was:<blockquote>" + exception.getMessage() + "</blockquote></blockquote>")); } }
java
@Override public void badRequest(final BadRequestException exception) { logWarn("Bad Request on " + request().getUri() + ": " + exception.getMessage()); if (this.api_version > 0) { // always default to the latest version of the error formatter since we // need to return something switch (this.api_version) { case 1: default: sendReply(exception.getStatus(), serializer.formatErrorV1(exception)); } return; } if (hasQueryStringParam("json")) { final StringBuilder buf = new StringBuilder(10 + exception.getDetails().length()); buf.append("{\"err\":\""); HttpQuery.escapeJson(exception.getMessage(), buf); buf.append("\"}"); sendReply(HttpResponseStatus.BAD_REQUEST, buf); } else { sendReply(HttpResponseStatus.BAD_REQUEST, makePage("Bad Request", "Looks like it's your fault this time", "<blockquote>" + "<h1>Bad Request</h1>" + "Sorry but your request was rejected as being" + " invalid.<br/><br/>" + "The reason provided was:<blockquote>" + exception.getMessage() + "</blockquote></blockquote>")); } }
[ "@", "Override", "public", "void", "badRequest", "(", "final", "BadRequestException", "exception", ")", "{", "logWarn", "(", "\"Bad Request on \"", "+", "request", "(", ")", ".", "getUri", "(", ")", "+", "\": \"", "+", "exception", ".", "getMessage", "(", ")", ")", ";", "if", "(", "this", ".", "api_version", ">", "0", ")", "{", "// always default to the latest version of the error formatter since we", "// need to return something", "switch", "(", "this", ".", "api_version", ")", "{", "case", "1", ":", "default", ":", "sendReply", "(", "exception", ".", "getStatus", "(", ")", ",", "serializer", ".", "formatErrorV1", "(", "exception", ")", ")", ";", "}", "return", ";", "}", "if", "(", "hasQueryStringParam", "(", "\"json\"", ")", ")", "{", "final", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "10", "+", "exception", ".", "getDetails", "(", ")", ".", "length", "(", ")", ")", ";", "buf", ".", "append", "(", "\"{\\\"err\\\":\\\"\"", ")", ";", "HttpQuery", ".", "escapeJson", "(", "exception", ".", "getMessage", "(", ")", ",", "buf", ")", ";", "buf", ".", "append", "(", "\"\\\"}\"", ")", ";", "sendReply", "(", "HttpResponseStatus", ".", "BAD_REQUEST", ",", "buf", ")", ";", "}", "else", "{", "sendReply", "(", "HttpResponseStatus", ".", "BAD_REQUEST", ",", "makePage", "(", "\"Bad Request\"", ",", "\"Looks like it's your fault this time\"", ",", "\"<blockquote>\"", "+", "\"<h1>Bad Request</h1>\"", "+", "\"Sorry but your request was rejected as being\"", "+", "\" invalid.<br/><br/>\"", "+", "\"The reason provided was:<blockquote>\"", "+", "exception", ".", "getMessage", "(", ")", "+", "\"</blockquote></blockquote>\"", ")", ")", ";", "}", "}" ]
Sends an error message to the client. Handles responses from deprecated API calls. @param exception The exception that was thrown
[ "Sends", "an", "error", "message", "to", "the", "client", ".", "Handles", "responses", "from", "deprecated", "API", "calls", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L402-L433
13,469
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.notFound
@Override public void notFound() { logWarn("Not Found: " + request().getUri()); if (this.api_version > 0) { // always default to the latest version of the error formatter since we // need to return something switch (this.api_version) { case 1: default: sendReply(HttpResponseStatus.NOT_FOUND, serializer.formatNotFoundV1()); } return; } if (hasQueryStringParam("json")) { sendReply(HttpResponseStatus.NOT_FOUND, new StringBuilder("{\"err\":\"Page Not Found\"}")); } else { sendReply(HttpResponseStatus.NOT_FOUND, PAGE_NOT_FOUND); } }
java
@Override public void notFound() { logWarn("Not Found: " + request().getUri()); if (this.api_version > 0) { // always default to the latest version of the error formatter since we // need to return something switch (this.api_version) { case 1: default: sendReply(HttpResponseStatus.NOT_FOUND, serializer.formatNotFoundV1()); } return; } if (hasQueryStringParam("json")) { sendReply(HttpResponseStatus.NOT_FOUND, new StringBuilder("{\"err\":\"Page Not Found\"}")); } else { sendReply(HttpResponseStatus.NOT_FOUND, PAGE_NOT_FOUND); } }
[ "@", "Override", "public", "void", "notFound", "(", ")", "{", "logWarn", "(", "\"Not Found: \"", "+", "request", "(", ")", ".", "getUri", "(", ")", ")", ";", "if", "(", "this", ".", "api_version", ">", "0", ")", "{", "// always default to the latest version of the error formatter since we", "// need to return something", "switch", "(", "this", ".", "api_version", ")", "{", "case", "1", ":", "default", ":", "sendReply", "(", "HttpResponseStatus", ".", "NOT_FOUND", ",", "serializer", ".", "formatNotFoundV1", "(", ")", ")", ";", "}", "return", ";", "}", "if", "(", "hasQueryStringParam", "(", "\"json\"", ")", ")", "{", "sendReply", "(", "HttpResponseStatus", ".", "NOT_FOUND", ",", "new", "StringBuilder", "(", "\"{\\\"err\\\":\\\"Page Not Found\\\"}\"", ")", ")", ";", "}", "else", "{", "sendReply", "(", "HttpResponseStatus", ".", "NOT_FOUND", ",", "PAGE_NOT_FOUND", ")", ";", "}", "}" ]
Sends a 404 error page to the client. Handles responses from deprecated API calls
[ "Sends", "a", "404", "error", "page", "to", "the", "client", ".", "Handles", "responses", "from", "deprecated", "API", "calls" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L439-L458
13,470
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.redirect
public void redirect(final String location) { // set the header AND a meta refresh just in case response().headers().set("Location", location); sendReply(HttpResponseStatus.OK, new StringBuilder( "<html></head><meta http-equiv=\"refresh\" content=\"0; url=" + location + "\"></head></html>") .toString().getBytes(this.getCharset()) ); }
java
public void redirect(final String location) { // set the header AND a meta refresh just in case response().headers().set("Location", location); sendReply(HttpResponseStatus.OK, new StringBuilder( "<html></head><meta http-equiv=\"refresh\" content=\"0; url=" + location + "\"></head></html>") .toString().getBytes(this.getCharset()) ); }
[ "public", "void", "redirect", "(", "final", "String", "location", ")", "{", "// set the header AND a meta refresh just in case", "response", "(", ")", ".", "headers", "(", ")", ".", "set", "(", "\"Location\"", ",", "location", ")", ";", "sendReply", "(", "HttpResponseStatus", ".", "OK", ",", "new", "StringBuilder", "(", "\"<html></head><meta http-equiv=\\\"refresh\\\" content=\\\"0; url=\"", "+", "location", "+", "\"\\\"></head></html>\"", ")", ".", "toString", "(", ")", ".", "getBytes", "(", "this", ".", "getCharset", "(", ")", ")", ")", ";", "}" ]
Redirects the client's browser to the given location.
[ "Redirects", "the", "client", "s", "browser", "to", "the", "given", "location", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L461-L470
13,471
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.escapeJson
static void escapeJson(final String s, final StringBuilder buf) { final int length = s.length(); int extra = 0; // First count how many extra chars we'll need, if any. for (int i = 0; i < length; i++) { final char c = s.charAt(i); switch (c) { case '"': case '\\': case '\b': case '\f': case '\n': case '\r': case '\t': extra++; continue; } if (c < 0x001F) { extra += 4; } } if (extra == 0) { buf.append(s); // Nothing to escape. return; } buf.ensureCapacity(buf.length() + length + extra); for (int i = 0; i < length; i++) { final char c = s.charAt(i); switch (c) { case '"': buf.append('\\').append('"'); continue; case '\\': buf.append('\\').append('\\'); continue; case '\b': buf.append('\\').append('b'); continue; case '\f': buf.append('\\').append('f'); continue; case '\n': buf.append('\\').append('n'); continue; case '\r': buf.append('\\').append('r'); continue; case '\t': buf.append('\\').append('t'); continue; } if (c < 0x001F) { buf.append('\\').append('u').append('0').append('0') .append((char) Const.HEX[(c >>> 4) & 0x0F]) .append((char) Const.HEX[c & 0x0F]); } else { buf.append(c); } } }
java
static void escapeJson(final String s, final StringBuilder buf) { final int length = s.length(); int extra = 0; // First count how many extra chars we'll need, if any. for (int i = 0; i < length; i++) { final char c = s.charAt(i); switch (c) { case '"': case '\\': case '\b': case '\f': case '\n': case '\r': case '\t': extra++; continue; } if (c < 0x001F) { extra += 4; } } if (extra == 0) { buf.append(s); // Nothing to escape. return; } buf.ensureCapacity(buf.length() + length + extra); for (int i = 0; i < length; i++) { final char c = s.charAt(i); switch (c) { case '"': buf.append('\\').append('"'); continue; case '\\': buf.append('\\').append('\\'); continue; case '\b': buf.append('\\').append('b'); continue; case '\f': buf.append('\\').append('f'); continue; case '\n': buf.append('\\').append('n'); continue; case '\r': buf.append('\\').append('r'); continue; case '\t': buf.append('\\').append('t'); continue; } if (c < 0x001F) { buf.append('\\').append('u').append('0').append('0') .append((char) Const.HEX[(c >>> 4) & 0x0F]) .append((char) Const.HEX[c & 0x0F]); } else { buf.append(c); } } }
[ "static", "void", "escapeJson", "(", "final", "String", "s", ",", "final", "StringBuilder", "buf", ")", "{", "final", "int", "length", "=", "s", ".", "length", "(", ")", ";", "int", "extra", "=", "0", ";", "// First count how many extra chars we'll need, if any.", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "final", "char", "c", "=", "s", ".", "charAt", "(", "i", ")", ";", "switch", "(", "c", ")", "{", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "extra", "++", ";", "continue", ";", "}", "if", "(", "c", "<", "0x001F", ")", "{", "extra", "+=", "4", ";", "}", "}", "if", "(", "extra", "==", "0", ")", "{", "buf", ".", "append", "(", "s", ")", ";", "// Nothing to escape.", "return", ";", "}", "buf", ".", "ensureCapacity", "(", "buf", ".", "length", "(", ")", "+", "length", "+", "extra", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "final", "char", "c", "=", "s", ".", "charAt", "(", "i", ")", ";", "switch", "(", "c", ")", "{", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "case", "'", "'", ":", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ";", "continue", ";", "}", "if", "(", "c", "<", "0x001F", ")", "{", "buf", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ".", "append", "(", "'", "'", ")", ".", "append", "(", "(", "char", ")", "Const", ".", "HEX", "[", "(", "c", ">>>", "4", ")", "&", "0x0F", "]", ")", ".", "append", "(", "(", "char", ")", "Const", ".", "HEX", "[", "c", "&", "0x0F", "]", ")", ";", "}", "else", "{", "buf", ".", "append", "(", "c", ")", ";", "}", "}", "}" ]
Escapes a string appropriately to be a valid in JSON. Valid JSON strings are defined in RFC 4627, Section 2.5. @param s The string to escape, which is assumed to be in . @param buf The buffer into which to write the escaped string.
[ "Escapes", "a", "string", "appropriately", "to", "be", "a", "valid", "in", "JSON", ".", "Valid", "JSON", "strings", "are", "defined", "in", "RFC", "4627", "Section", "2", ".", "5", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L478-L523
13,472
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.done
@Override public void done() { final int processing_time = processingTimeMillis(); httplatency.add(processing_time); logInfo("HTTP " + request().getUri() + " done in " + processing_time + "ms"); deferred.callback(null); }
java
@Override public void done() { final int processing_time = processingTimeMillis(); httplatency.add(processing_time); logInfo("HTTP " + request().getUri() + " done in " + processing_time + "ms"); deferred.callback(null); }
[ "@", "Override", "public", "void", "done", "(", ")", "{", "final", "int", "processing_time", "=", "processingTimeMillis", "(", ")", ";", "httplatency", ".", "add", "(", "processing_time", ")", ";", "logInfo", "(", "\"HTTP \"", "+", "request", "(", ")", ".", "getUri", "(", ")", "+", "\" done in \"", "+", "processing_time", "+", "\"ms\"", ")", ";", "deferred", ".", "callback", "(", "null", ")", ";", "}" ]
Method to call after writing the HTTP response to the wire.
[ "Method", "to", "call", "after", "writing", "the", "HTTP", "response", "to", "the", "wire", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L685-L691
13,473
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.guessMimeType
private String guessMimeType(final ChannelBuffer buf) { final String mimetype = guessMimeTypeFromUri(request().getUri()); return mimetype == null ? guessMimeTypeFromContents(buf) : mimetype; }
java
private String guessMimeType(final ChannelBuffer buf) { final String mimetype = guessMimeTypeFromUri(request().getUri()); return mimetype == null ? guessMimeTypeFromContents(buf) : mimetype; }
[ "private", "String", "guessMimeType", "(", "final", "ChannelBuffer", "buf", ")", "{", "final", "String", "mimetype", "=", "guessMimeTypeFromUri", "(", "request", "(", ")", ".", "getUri", "(", ")", ")", ";", "return", "mimetype", "==", "null", "?", "guessMimeTypeFromContents", "(", "buf", ")", ":", "mimetype", ";", "}" ]
Returns the result of an attempt to guess the MIME type of the response. @param buf The content of the reply to send.
[ "Returns", "the", "result", "of", "an", "attempt", "to", "guess", "the", "MIME", "type", "of", "the", "response", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L709-L712
13,474
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.guessMimeTypeFromUri
private static String guessMimeTypeFromUri(final String uri) { final int questionmark = uri.indexOf('?', 1); // 1 => skip the initial / final int end = (questionmark > 0 ? questionmark : uri.length()) - 1; if (end < 5) { // Need at least: "/a.js" return null; } final char a = uri.charAt(end - 3); final char b = uri.charAt(end - 2); final char c = uri.charAt(end - 1); switch (uri.charAt(end)) { case 'g': return a == '.' && b == 'p' && c == 'n' ? "image/png" : null; case 'l': return a == 'h' && b == 't' && c == 'm' ? HTML_CONTENT_TYPE : null; case 's': if (a == '.' && b == 'c' && c == 's') { return "text/css"; } else if (b == '.' && c == 'j') { return "text/javascript"; } else { break; } case 'f': return a == '.' && b == 'g' && c == 'i' ? "image/gif" : null; case 'o': return a == '.' && b == 'i' && c == 'c' ? "image/x-icon" : null; } return null; }
java
private static String guessMimeTypeFromUri(final String uri) { final int questionmark = uri.indexOf('?', 1); // 1 => skip the initial / final int end = (questionmark > 0 ? questionmark : uri.length()) - 1; if (end < 5) { // Need at least: "/a.js" return null; } final char a = uri.charAt(end - 3); final char b = uri.charAt(end - 2); final char c = uri.charAt(end - 1); switch (uri.charAt(end)) { case 'g': return a == '.' && b == 'p' && c == 'n' ? "image/png" : null; case 'l': return a == 'h' && b == 't' && c == 'm' ? HTML_CONTENT_TYPE : null; case 's': if (a == '.' && b == 'c' && c == 's') { return "text/css"; } else if (b == '.' && c == 'j') { return "text/javascript"; } else { break; } case 'f': return a == '.' && b == 'g' && c == 'i' ? "image/gif" : null; case 'o': return a == '.' && b == 'i' && c == 'c' ? "image/x-icon" : null; } return null; }
[ "private", "static", "String", "guessMimeTypeFromUri", "(", "final", "String", "uri", ")", "{", "final", "int", "questionmark", "=", "uri", ".", "indexOf", "(", "'", "'", ",", "1", ")", ";", "// 1 => skip the initial /", "final", "int", "end", "=", "(", "questionmark", ">", "0", "?", "questionmark", ":", "uri", ".", "length", "(", ")", ")", "-", "1", ";", "if", "(", "end", "<", "5", ")", "{", "// Need at least: \"/a.js\"", "return", "null", ";", "}", "final", "char", "a", "=", "uri", ".", "charAt", "(", "end", "-", "3", ")", ";", "final", "char", "b", "=", "uri", ".", "charAt", "(", "end", "-", "2", ")", ";", "final", "char", "c", "=", "uri", ".", "charAt", "(", "end", "-", "1", ")", ";", "switch", "(", "uri", ".", "charAt", "(", "end", ")", ")", "{", "case", "'", "'", ":", "return", "a", "==", "'", "'", "&&", "b", "==", "'", "'", "&&", "c", "==", "'", "'", "?", "\"image/png\"", ":", "null", ";", "case", "'", "'", ":", "return", "a", "==", "'", "'", "&&", "b", "==", "'", "'", "&&", "c", "==", "'", "'", "?", "HTML_CONTENT_TYPE", ":", "null", ";", "case", "'", "'", ":", "if", "(", "a", "==", "'", "'", "&&", "b", "==", "'", "'", "&&", "c", "==", "'", "'", ")", "{", "return", "\"text/css\"", ";", "}", "else", "if", "(", "b", "==", "'", "'", "&&", "c", "==", "'", "'", ")", "{", "return", "\"text/javascript\"", ";", "}", "else", "{", "break", ";", "}", "case", "'", "'", ":", "return", "a", "==", "'", "'", "&&", "b", "==", "'", "'", "&&", "c", "==", "'", "'", "?", "\"image/gif\"", ":", "null", ";", "case", "'", "'", ":", "return", "a", "==", "'", "'", "&&", "b", "==", "'", "'", "&&", "c", "==", "'", "'", "?", "\"image/x-icon\"", ":", "null", ";", "}", "return", "null", ";", "}" ]
Attempts to guess the MIME type by looking at the URI requested. @param uri The URI from which to infer the MIME type.
[ "Attempts", "to", "guess", "the", "MIME", "type", "by", "looking", "at", "the", "URI", "requested", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L718-L746
13,475
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.guessMimeTypeFromContents
private String guessMimeTypeFromContents(final ChannelBuffer buf) { if (!buf.readable()) { logWarn("Sending an empty result?! buf=" + buf); return "text/plain"; } final int firstbyte = buf.getUnsignedByte(buf.readerIndex()); switch (firstbyte) { case '<': // <html or <!DOCTYPE return HTML_CONTENT_TYPE; case '{': // JSON object case '[': // JSON array return "application/json"; // RFC 4627 section 6 mandates this. case 0x89: // magic number in PNG files. return "image/png"; } return "text/plain"; // Default. }
java
private String guessMimeTypeFromContents(final ChannelBuffer buf) { if (!buf.readable()) { logWarn("Sending an empty result?! buf=" + buf); return "text/plain"; } final int firstbyte = buf.getUnsignedByte(buf.readerIndex()); switch (firstbyte) { case '<': // <html or <!DOCTYPE return HTML_CONTENT_TYPE; case '{': // JSON object case '[': // JSON array return "application/json"; // RFC 4627 section 6 mandates this. case 0x89: // magic number in PNG files. return "image/png"; } return "text/plain"; // Default. }
[ "private", "String", "guessMimeTypeFromContents", "(", "final", "ChannelBuffer", "buf", ")", "{", "if", "(", "!", "buf", ".", "readable", "(", ")", ")", "{", "logWarn", "(", "\"Sending an empty result?! buf=\"", "+", "buf", ")", ";", "return", "\"text/plain\"", ";", "}", "final", "int", "firstbyte", "=", "buf", ".", "getUnsignedByte", "(", "buf", ".", "readerIndex", "(", ")", ")", ";", "switch", "(", "firstbyte", ")", "{", "case", "'", "'", ":", "// <html or <!DOCTYPE", "return", "HTML_CONTENT_TYPE", ";", "case", "'", "'", ":", "// JSON object", "case", "'", "'", ":", "// JSON array", "return", "\"application/json\"", ";", "// RFC 4627 section 6 mandates this.", "case", "0x89", ":", "// magic number in PNG files.", "return", "\"image/png\"", ";", "}", "return", "\"text/plain\"", ";", "// Default.", "}" ]
Simple "content sniffing". May not be a great idea, but will do until this class has a better API. @param buf The content of the reply to send. @return The MIME type guessed from {@code buf}.
[ "Simple", "content", "sniffing", ".", "May", "not", "be", "a", "great", "idea", "but", "will", "do", "until", "this", "class", "has", "a", "better", "API", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L754-L770
13,476
OpenTSDB/opentsdb
src/tsd/HttpQuery.java
HttpQuery.makePage
public static StringBuilder makePage(final String htmlheader, final String title, final String subtitle, final String body) { final StringBuilder buf = new StringBuilder( BOILERPLATE_LENGTH + (htmlheader == null ? 0 : htmlheader.length()) + title.length() + subtitle.length() + body.length()); buf.append(PAGE_HEADER_START) .append(title) .append(PAGE_HEADER_MID); if (htmlheader != null) { buf.append(htmlheader); } buf.append(PAGE_HEADER_END_BODY_START) .append(subtitle) .append(PAGE_BODY_MID) .append(body) .append(PAGE_FOOTER); return buf; }
java
public static StringBuilder makePage(final String htmlheader, final String title, final String subtitle, final String body) { final StringBuilder buf = new StringBuilder( BOILERPLATE_LENGTH + (htmlheader == null ? 0 : htmlheader.length()) + title.length() + subtitle.length() + body.length()); buf.append(PAGE_HEADER_START) .append(title) .append(PAGE_HEADER_MID); if (htmlheader != null) { buf.append(htmlheader); } buf.append(PAGE_HEADER_END_BODY_START) .append(subtitle) .append(PAGE_BODY_MID) .append(body) .append(PAGE_FOOTER); return buf; }
[ "public", "static", "StringBuilder", "makePage", "(", "final", "String", "htmlheader", ",", "final", "String", "title", ",", "final", "String", "subtitle", ",", "final", "String", "body", ")", "{", "final", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "BOILERPLATE_LENGTH", "+", "(", "htmlheader", "==", "null", "?", "0", ":", "htmlheader", ".", "length", "(", ")", ")", "+", "title", ".", "length", "(", ")", "+", "subtitle", ".", "length", "(", ")", "+", "body", ".", "length", "(", ")", ")", ";", "buf", ".", "append", "(", "PAGE_HEADER_START", ")", ".", "append", "(", "title", ")", ".", "append", "(", "PAGE_HEADER_MID", ")", ";", "if", "(", "htmlheader", "!=", "null", ")", "{", "buf", ".", "append", "(", "htmlheader", ")", ";", "}", "buf", ".", "append", "(", "PAGE_HEADER_END_BODY_START", ")", ".", "append", "(", "subtitle", ")", ".", "append", "(", "PAGE_BODY_MID", ")", ".", "append", "(", "body", ")", ".", "append", "(", "PAGE_FOOTER", ")", ";", "return", "buf", ";", "}" ]
Easy way to generate a small, simple HTML page. @param htmlheader Text to insert in the {@code head} tag. Ignored if {@code null}. @param title What should be in the {@code title} tag of the page. @param subtitle Small sentence to use next to the TSD logo. @param body The body of the page (excluding the {@code body} tag). @return A full HTML page.
[ "Easy", "way", "to", "generate", "a", "small", "simple", "HTML", "page", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/HttpQuery.java#L929-L948
13,477
OpenTSDB/opentsdb
src/tools/FsckOptions.java
FsckOptions.addDataOptions
public static void addDataOptions(final ArgP argp) { argp.addOption("--full-scan", "Scan the entire data table."); argp.addOption("--fix", "Fix errors as they're found. Use in combination with" + " other flags."); argp.addOption("--fix-all", "Set all flags and fix errors as they're found."); argp.addOption("--compact", "Compacts rows after parsing."); argp.addOption("--resolve-duplicates", "Keeps the oldest (default) or newest duplicates. See --last-write-wins"); argp.addOption("--last-write-wins", "Last data point written will be kept when fixing duplicates.\n" + " May be set via config file and the 'tsd.storage.fix_duplicates' option."); argp.addOption("--delete-orphans", "Delete any time series rows where one or more UIDs fail resolution."); argp.addOption("--delete-unknown-columns", "Delete any unrecognized column that doesn't belong to OpenTSDB."); argp.addOption("--delete-bad-values", "Delete single column datapoints with bad values."); argp.addOption("--delete-bad-rows", "Delete rows with invalid keys."); argp.addOption("--delete-bad-compacts", "Delete compacted columns that cannot be parsed."); argp.addOption("--threads", "NUMBER", "Number of threads to use when executing a full table scan."); argp.addOption("--sync", "Wait for each fix operation to finish to continue."); }
java
public static void addDataOptions(final ArgP argp) { argp.addOption("--full-scan", "Scan the entire data table."); argp.addOption("--fix", "Fix errors as they're found. Use in combination with" + " other flags."); argp.addOption("--fix-all", "Set all flags and fix errors as they're found."); argp.addOption("--compact", "Compacts rows after parsing."); argp.addOption("--resolve-duplicates", "Keeps the oldest (default) or newest duplicates. See --last-write-wins"); argp.addOption("--last-write-wins", "Last data point written will be kept when fixing duplicates.\n" + " May be set via config file and the 'tsd.storage.fix_duplicates' option."); argp.addOption("--delete-orphans", "Delete any time series rows where one or more UIDs fail resolution."); argp.addOption("--delete-unknown-columns", "Delete any unrecognized column that doesn't belong to OpenTSDB."); argp.addOption("--delete-bad-values", "Delete single column datapoints with bad values."); argp.addOption("--delete-bad-rows", "Delete rows with invalid keys."); argp.addOption("--delete-bad-compacts", "Delete compacted columns that cannot be parsed."); argp.addOption("--threads", "NUMBER", "Number of threads to use when executing a full table scan."); argp.addOption("--sync", "Wait for each fix operation to finish to continue."); }
[ "public", "static", "void", "addDataOptions", "(", "final", "ArgP", "argp", ")", "{", "argp", ".", "addOption", "(", "\"--full-scan\"", ",", "\"Scan the entire data table.\"", ")", ";", "argp", ".", "addOption", "(", "\"--fix\"", ",", "\"Fix errors as they're found. Use in combination with\"", "+", "\" other flags.\"", ")", ";", "argp", ".", "addOption", "(", "\"--fix-all\"", ",", "\"Set all flags and fix errors as they're found.\"", ")", ";", "argp", ".", "addOption", "(", "\"--compact\"", ",", "\"Compacts rows after parsing.\"", ")", ";", "argp", ".", "addOption", "(", "\"--resolve-duplicates\"", ",", "\"Keeps the oldest (default) or newest duplicates. See --last-write-wins\"", ")", ";", "argp", ".", "addOption", "(", "\"--last-write-wins\"", ",", "\"Last data point written will be kept when fixing duplicates.\\n\"", "+", "\" May be set via config file and the 'tsd.storage.fix_duplicates' option.\"", ")", ";", "argp", ".", "addOption", "(", "\"--delete-orphans\"", ",", "\"Delete any time series rows where one or more UIDs fail resolution.\"", ")", ";", "argp", ".", "addOption", "(", "\"--delete-unknown-columns\"", ",", "\"Delete any unrecognized column that doesn't belong to OpenTSDB.\"", ")", ";", "argp", ".", "addOption", "(", "\"--delete-bad-values\"", ",", "\"Delete single column datapoints with bad values.\"", ")", ";", "argp", ".", "addOption", "(", "\"--delete-bad-rows\"", ",", "\"Delete rows with invalid keys.\"", ")", ";", "argp", ".", "addOption", "(", "\"--delete-bad-compacts\"", ",", "\"Delete compacted columns that cannot be parsed.\"", ")", ";", "argp", ".", "addOption", "(", "\"--threads\"", ",", "\"NUMBER\"", ",", "\"Number of threads to use when executing a full table scan.\"", ")", ";", "argp", ".", "addOption", "(", "\"--sync\"", ",", "\"Wait for each fix operation to finish to continue.\"", ")", ";", "}" ]
Add data table fsck options to the command line parser @param argp The parser to add options to
[ "Add", "data", "table", "fsck", "options", "to", "the", "command", "line", "parser" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/FsckOptions.java#L77-L100
13,478
OpenTSDB/opentsdb
src/query/expression/Absolute.java
Absolute.abs
private DataPoints abs(final DataPoints points) { // TODO(cl) - Using an array as the size function may not return the exact // results and we should figure a way to avoid copying data anyway. final List<DataPoint> dps = new ArrayList<DataPoint>(); final SeekableView view = points.iterator(); while (view.hasNext()) { DataPoint pt = view.next(); if (pt.isInteger()) { dps.add(MutableDataPoint.ofLongValue( pt.timestamp(), Math.abs(pt.longValue()))); } else { dps.add(MutableDataPoint.ofDoubleValue( pt.timestamp(), Math.abs(pt.doubleValue()))); } } final DataPoint[] results = new DataPoint[dps.size()]; dps.toArray(results); return new PostAggregatedDataPoints(points, results); }
java
private DataPoints abs(final DataPoints points) { // TODO(cl) - Using an array as the size function may not return the exact // results and we should figure a way to avoid copying data anyway. final List<DataPoint> dps = new ArrayList<DataPoint>(); final SeekableView view = points.iterator(); while (view.hasNext()) { DataPoint pt = view.next(); if (pt.isInteger()) { dps.add(MutableDataPoint.ofLongValue( pt.timestamp(), Math.abs(pt.longValue()))); } else { dps.add(MutableDataPoint.ofDoubleValue( pt.timestamp(), Math.abs(pt.doubleValue()))); } } final DataPoint[] results = new DataPoint[dps.size()]; dps.toArray(results); return new PostAggregatedDataPoints(points, results); }
[ "private", "DataPoints", "abs", "(", "final", "DataPoints", "points", ")", "{", "// TODO(cl) - Using an array as the size function may not return the exact", "// results and we should figure a way to avoid copying data anyway.", "final", "List", "<", "DataPoint", ">", "dps", "=", "new", "ArrayList", "<", "DataPoint", ">", "(", ")", ";", "final", "SeekableView", "view", "=", "points", ".", "iterator", "(", ")", ";", "while", "(", "view", ".", "hasNext", "(", ")", ")", "{", "DataPoint", "pt", "=", "view", ".", "next", "(", ")", ";", "if", "(", "pt", ".", "isInteger", "(", ")", ")", "{", "dps", ".", "add", "(", "MutableDataPoint", ".", "ofLongValue", "(", "pt", ".", "timestamp", "(", ")", ",", "Math", ".", "abs", "(", "pt", ".", "longValue", "(", ")", ")", ")", ")", ";", "}", "else", "{", "dps", ".", "add", "(", "MutableDataPoint", ".", "ofDoubleValue", "(", "pt", ".", "timestamp", "(", ")", ",", "Math", ".", "abs", "(", "pt", ".", "doubleValue", "(", ")", ")", ")", ")", ";", "}", "}", "final", "DataPoint", "[", "]", "results", "=", "new", "DataPoint", "[", "dps", ".", "size", "(", ")", "]", ";", "dps", ".", "toArray", "(", "results", ")", ";", "return", "new", "PostAggregatedDataPoints", "(", "points", ",", "results", ")", ";", "}" ]
Iterate over each data point and store the absolute value @param points The data points to modify @return The resulting data points
[ "Iterate", "over", "each", "data", "point", "and", "store", "the", "absolute", "value" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/Absolute.java#L63-L82
13,479
OpenTSDB/opentsdb
src/tree/TreeBuilder.java
TreeBuilder.processParsedValue
private void processParsedValue(final String parsed_value) { if (rule.getCompiledRegex() == null && (rule.getSeparator() == null || rule.getSeparator().isEmpty())) { // we don't have a regex and we don't need to separate, so just use the // name of the timseries setCurrentName(parsed_value, parsed_value); } else if (rule.getCompiledRegex() != null) { // we have a regex rule, so deal with it processRegexRule(parsed_value); } else if (rule.getSeparator() != null && !rule.getSeparator().isEmpty()) { // we have a split rule, so deal with it processSplit(parsed_value); } else { throw new IllegalStateException("Unable to find a processor for rule: " + rule); } }
java
private void processParsedValue(final String parsed_value) { if (rule.getCompiledRegex() == null && (rule.getSeparator() == null || rule.getSeparator().isEmpty())) { // we don't have a regex and we don't need to separate, so just use the // name of the timseries setCurrentName(parsed_value, parsed_value); } else if (rule.getCompiledRegex() != null) { // we have a regex rule, so deal with it processRegexRule(parsed_value); } else if (rule.getSeparator() != null && !rule.getSeparator().isEmpty()) { // we have a split rule, so deal with it processSplit(parsed_value); } else { throw new IllegalStateException("Unable to find a processor for rule: " + rule); } }
[ "private", "void", "processParsedValue", "(", "final", "String", "parsed_value", ")", "{", "if", "(", "rule", ".", "getCompiledRegex", "(", ")", "==", "null", "&&", "(", "rule", ".", "getSeparator", "(", ")", "==", "null", "||", "rule", ".", "getSeparator", "(", ")", ".", "isEmpty", "(", ")", ")", ")", "{", "// we don't have a regex and we don't need to separate, so just use the", "// name of the timseries", "setCurrentName", "(", "parsed_value", ",", "parsed_value", ")", ";", "}", "else", "if", "(", "rule", ".", "getCompiledRegex", "(", ")", "!=", "null", ")", "{", "// we have a regex rule, so deal with it", "processRegexRule", "(", "parsed_value", ")", ";", "}", "else", "if", "(", "rule", ".", "getSeparator", "(", ")", "!=", "null", "&&", "!", "rule", ".", "getSeparator", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "// we have a split rule, so deal with it", "processSplit", "(", "parsed_value", ")", ";", "}", "else", "{", "throw", "new", "IllegalStateException", "(", "\"Unable to find a processor for rule: \"", "+", "rule", ")", ";", "}", "}" ]
Routes the parsed value to the proper processing method for altering the display name depending on the current rule. This can route to the regex handler or the split processor. Or if neither splits or regex are specified for the rule, the parsed value is set as the branch name. @param parsed_value The value parsed from the calling parser method @throws IllegalStateException if a valid processor couldn't be found. This should never happen but you never know.
[ "Routes", "the", "parsed", "value", "to", "the", "proper", "processing", "method", "for", "altering", "the", "display", "name", "depending", "on", "the", "current", "rule", ".", "This", "can", "route", "to", "the", "regex", "handler", "or", "the", "split", "processor", ".", "Or", "if", "neither", "splits", "or", "regex", "are", "specified", "for", "the", "rule", "the", "parsed", "value", "is", "set", "as", "the", "branch", "name", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/TreeBuilder.java#L932-L948
13,480
OpenTSDB/opentsdb
src/tree/TreeBuilder.java
TreeBuilder.processRegexRule
private void processRegexRule(final String parsed_value) { if (rule.getCompiledRegex() == null) { throw new IllegalArgumentException("Regex was null for rule: " + rule); } final Matcher matcher = rule.getCompiledRegex().matcher(parsed_value); if (matcher.find()) { // The first group is always the full string, so we need to increment // by one to fetch the proper group if (matcher.groupCount() >= rule.getRegexGroupIdx() + 1) { final String extracted = matcher.group(rule.getRegexGroupIdx() + 1); if (extracted == null || extracted.isEmpty()) { // can't use empty values as a branch/leaf name testMessage("Extracted value for rule " + rule + " was null or empty"); } else { // found a branch or leaf! setCurrentName(parsed_value, extracted); } } else { // the group index was out of range testMessage("Regex group index [" + rule.getRegexGroupIdx() + "] for rule " + rule + " was out of bounds [" + matcher.groupCount() + "]"); } } }
java
private void processRegexRule(final String parsed_value) { if (rule.getCompiledRegex() == null) { throw new IllegalArgumentException("Regex was null for rule: " + rule); } final Matcher matcher = rule.getCompiledRegex().matcher(parsed_value); if (matcher.find()) { // The first group is always the full string, so we need to increment // by one to fetch the proper group if (matcher.groupCount() >= rule.getRegexGroupIdx() + 1) { final String extracted = matcher.group(rule.getRegexGroupIdx() + 1); if (extracted == null || extracted.isEmpty()) { // can't use empty values as a branch/leaf name testMessage("Extracted value for rule " + rule + " was null or empty"); } else { // found a branch or leaf! setCurrentName(parsed_value, extracted); } } else { // the group index was out of range testMessage("Regex group index [" + rule.getRegexGroupIdx() + "] for rule " + rule + " was out of bounds [" + matcher.groupCount() + "]"); } } }
[ "private", "void", "processRegexRule", "(", "final", "String", "parsed_value", ")", "{", "if", "(", "rule", ".", "getCompiledRegex", "(", ")", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Regex was null for rule: \"", "+", "rule", ")", ";", "}", "final", "Matcher", "matcher", "=", "rule", ".", "getCompiledRegex", "(", ")", ".", "matcher", "(", "parsed_value", ")", ";", "if", "(", "matcher", ".", "find", "(", ")", ")", "{", "// The first group is always the full string, so we need to increment", "// by one to fetch the proper group", "if", "(", "matcher", ".", "groupCount", "(", ")", ">=", "rule", ".", "getRegexGroupIdx", "(", ")", "+", "1", ")", "{", "final", "String", "extracted", "=", "matcher", ".", "group", "(", "rule", ".", "getRegexGroupIdx", "(", ")", "+", "1", ")", ";", "if", "(", "extracted", "==", "null", "||", "extracted", ".", "isEmpty", "(", ")", ")", "{", "// can't use empty values as a branch/leaf name", "testMessage", "(", "\"Extracted value for rule \"", "+", "rule", "+", "\" was null or empty\"", ")", ";", "}", "else", "{", "// found a branch or leaf!", "setCurrentName", "(", "parsed_value", ",", "extracted", ")", ";", "}", "}", "else", "{", "// the group index was out of range", "testMessage", "(", "\"Regex group index [\"", "+", "rule", ".", "getRegexGroupIdx", "(", ")", "+", "\"] for rule \"", "+", "rule", "+", "\" was out of bounds [\"", "+", "matcher", ".", "groupCount", "(", ")", "+", "\"]\"", ")", ";", "}", "}", "}" ]
Runs the parsed string through a regex and attempts to extract a value from the specified group index. Group indexes start at 0. If the regex was not matched, or an extracted value for the requested group did not exist, then the processor returns and the rule will be considered a no-match. @param parsed_value The value parsed from the calling parser method @throws IllegalStateException if the rule regex was null
[ "Runs", "the", "parsed", "string", "through", "a", "regex", "and", "attempts", "to", "extract", "a", "value", "from", "the", "specified", "group", "index", ".", "Group", "indexes", "start", "at", "0", ".", "If", "the", "regex", "was", "not", "matched", "or", "an", "extracted", "value", "for", "the", "requested", "group", "did", "not", "exist", "then", "the", "processor", "returns", "and", "the", "rule", "will", "be", "considered", "a", "no", "-", "match", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/TreeBuilder.java#L1003-L1032
13,481
OpenTSDB/opentsdb
src/tree/TreeBuilder.java
TreeBuilder.resetState
private void resetState() { meta = null; splits = null; rule_idx = 0; split_idx = 0; current_branch = null; rule = null; not_matched = null; if (root != null) { if (root.getBranches() != null) { root.getBranches().clear(); } if (root.getLeaves() != null) { root.getLeaves().clear(); } } test_messages = new ArrayList<String>(); }
java
private void resetState() { meta = null; splits = null; rule_idx = 0; split_idx = 0; current_branch = null; rule = null; not_matched = null; if (root != null) { if (root.getBranches() != null) { root.getBranches().clear(); } if (root.getLeaves() != null) { root.getLeaves().clear(); } } test_messages = new ArrayList<String>(); }
[ "private", "void", "resetState", "(", ")", "{", "meta", "=", "null", ";", "splits", "=", "null", ";", "rule_idx", "=", "0", ";", "split_idx", "=", "0", ";", "current_branch", "=", "null", ";", "rule", "=", "null", ";", "not_matched", "=", "null", ";", "if", "(", "root", "!=", "null", ")", "{", "if", "(", "root", ".", "getBranches", "(", ")", "!=", "null", ")", "{", "root", ".", "getBranches", "(", ")", ".", "clear", "(", ")", ";", "}", "if", "(", "root", ".", "getLeaves", "(", ")", "!=", "null", ")", "{", "root", ".", "getLeaves", "(", ")", ".", "clear", "(", ")", ";", "}", "}", "test_messages", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "}" ]
Resets local state variables to their defaults
[ "Resets", "local", "state", "variables", "to", "their", "defaults" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/TreeBuilder.java#L1143-L1160
13,482
OpenTSDB/opentsdb
src/tsd/RTPublisher.java
RTPublisher.sinkDataPoint
public final Deferred<Object> sinkDataPoint(final String metric, final long timestamp, final byte[] value, final Map<String, String> tags, final byte[] tsuid, final short flags) { if ((flags & Const.FLAG_FLOAT) != 0x0) { return publishDataPoint(metric, timestamp, Internal.extractFloatingPointValue(value, 0, (byte) flags), tags, tsuid); } else { return publishDataPoint(metric, timestamp, Internal.extractIntegerValue(value, 0, (byte) flags), tags, tsuid); } }
java
public final Deferred<Object> sinkDataPoint(final String metric, final long timestamp, final byte[] value, final Map<String, String> tags, final byte[] tsuid, final short flags) { if ((flags & Const.FLAG_FLOAT) != 0x0) { return publishDataPoint(metric, timestamp, Internal.extractFloatingPointValue(value, 0, (byte) flags), tags, tsuid); } else { return publishDataPoint(metric, timestamp, Internal.extractIntegerValue(value, 0, (byte) flags), tags, tsuid); } }
[ "public", "final", "Deferred", "<", "Object", ">", "sinkDataPoint", "(", "final", "String", "metric", ",", "final", "long", "timestamp", ",", "final", "byte", "[", "]", "value", ",", "final", "Map", "<", "String", ",", "String", ">", "tags", ",", "final", "byte", "[", "]", "tsuid", ",", "final", "short", "flags", ")", "{", "if", "(", "(", "flags", "&", "Const", ".", "FLAG_FLOAT", ")", "!=", "0x0", ")", "{", "return", "publishDataPoint", "(", "metric", ",", "timestamp", ",", "Internal", ".", "extractFloatingPointValue", "(", "value", ",", "0", ",", "(", "byte", ")", "flags", ")", ",", "tags", ",", "tsuid", ")", ";", "}", "else", "{", "return", "publishDataPoint", "(", "metric", ",", "timestamp", ",", "Internal", ".", "extractIntegerValue", "(", "value", ",", "0", ",", "(", "byte", ")", "flags", ")", ",", "tags", ",", "tsuid", ")", ";", "}", "}" ]
Called by the TSD when a new, raw data point is published. Because this is called after a data point is queued, the value has been converted to a byte array so we need to convert it back to an integer or floating point value. Instead of requiring every implementation to perform the calculation we perform it here and let the implementer deal with the integer or float. @param metric The name of the metric associated with the data point @param timestamp Timestamp as a Unix epoch in seconds or milliseconds (depending on the TSD's configuration) @param value The value as a byte array @param tags Tagk/v pairs @param tsuid Time series UID for the value @param flags Indicates if the byte array is an integer or floating point value @return A deferred without special meaning to wait on if necessary. The value may be null but a Deferred must be returned.
[ "Called", "by", "the", "TSD", "when", "a", "new", "raw", "data", "point", "is", "published", ".", "Because", "this", "is", "called", "after", "a", "data", "point", "is", "queued", "the", "value", "has", "been", "converted", "to", "a", "byte", "array", "so", "we", "need", "to", "convert", "it", "back", "to", "an", "integer", "or", "floating", "point", "value", ".", "Instead", "of", "requiring", "every", "implementation", "to", "perform", "the", "calculation", "we", "perform", "it", "here", "and", "let", "the", "implementer", "deal", "with", "the", "integer", "or", "float", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/RTPublisher.java#L97-L108
13,483
OpenTSDB/opentsdb
src/tsd/RTPublisher.java
RTPublisher.publishHistogramPoint
public Deferred<Object> publishHistogramPoint(final String metric, final long timestamp, final byte[] value, final Map<String, String> tags, final byte[] tsuid) { throw new UnsupportedOperationException("Not yet implemented"); }
java
public Deferred<Object> publishHistogramPoint(final String metric, final long timestamp, final byte[] value, final Map<String, String> tags, final byte[] tsuid) { throw new UnsupportedOperationException("Not yet implemented"); }
[ "public", "Deferred", "<", "Object", ">", "publishHistogramPoint", "(", "final", "String", "metric", ",", "final", "long", "timestamp", ",", "final", "byte", "[", "]", "value", ",", "final", "Map", "<", "String", ",", "String", ">", "tags", ",", "final", "byte", "[", "]", "tsuid", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Not yet implemented\"", ")", ";", "}" ]
Called any time a new histogram point is published @param metric The name of the metric associated with the data point @param timestamp Timestamp as a Unix epoch in seconds or milliseconds (depending on the TSD's configuration) @param value Encoded raw data blob for the histogram point @param tags Tagk/v pairs @param tsuid Time series UID for the value @return A deferred without special meaning to wait on if necessary. The value may be null but a Deferred must be returned.
[ "Called", "any", "time", "a", "new", "histogram", "point", "is", "published" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/RTPublisher.java#L159-L164
13,484
OpenTSDB/opentsdb
src/rollup/RollupInterval.java
RollupInterval.validateAndCompile
void validateAndCompile() { if (temporal_table_name == null || temporal_table_name.isEmpty()) { throw new IllegalArgumentException("The rollup table cannot be null or empty"); } temporal_table = temporal_table_name.getBytes(Const.ASCII_CHARSET); if (groupby_table_name == null || groupby_table_name.isEmpty()) { throw new IllegalArgumentException("The pre-aggregate rollup table cannot" + " be null or empty"); } groupby_table = groupby_table_name.getBytes(Const.ASCII_CHARSET); if (units != 'h' && unit_multiplier > 1) { throw new IllegalArgumentException("Multipliers are only usable with the 'h' unit"); } else if (units == 'h' && unit_multiplier > 1 && unit_multiplier % 2 != 0) { throw new IllegalArgumentException("The multiplier must be 1 or an even value"); } interval = (int) (DateTime.parseDuration(string_interval) / 1000); if (interval < 1) { throw new IllegalArgumentException("Millisecond intervals are not supported"); } if (interval >= Integer.MAX_VALUE) { throw new IllegalArgumentException("Interval is too big: " + interval); } // The line above will validate for us interval_units = string_interval.charAt(string_interval.length() - 1); int num_span = 0; switch (units) { case 'h': num_span = MAX_SECONDS_IN_HOUR; break; case 'd': num_span = MAX_SECONDS_IN_DAY; break; case 'n': num_span = MAX_SECONDS_IN_MONTH; break; case 'y': num_span = MAX_SECONDS_IN_YEAR; break; default: throw new IllegalArgumentException("Unrecogznied span '" + units + "'"); } num_span *= unit_multiplier; if (interval >= num_span) { throw new IllegalArgumentException("Interval [" + interval + "] is too large for the span [" + units + "]"); } intervals = num_span / (int)interval; if (intervals > MAX_INTERVALS) { throw new IllegalArgumentException("Too many intervals [" + intervals + "] in the span. Must be smaller than [" + MAX_INTERVALS + "] to fit in 14 bits"); } if (intervals < MIN_INTERVALS) { throw new IllegalArgumentException("Not enough intervals [" + intervals + "] for the span. Must be at least [" + MIN_INTERVALS + "]"); } }
java
void validateAndCompile() { if (temporal_table_name == null || temporal_table_name.isEmpty()) { throw new IllegalArgumentException("The rollup table cannot be null or empty"); } temporal_table = temporal_table_name.getBytes(Const.ASCII_CHARSET); if (groupby_table_name == null || groupby_table_name.isEmpty()) { throw new IllegalArgumentException("The pre-aggregate rollup table cannot" + " be null or empty"); } groupby_table = groupby_table_name.getBytes(Const.ASCII_CHARSET); if (units != 'h' && unit_multiplier > 1) { throw new IllegalArgumentException("Multipliers are only usable with the 'h' unit"); } else if (units == 'h' && unit_multiplier > 1 && unit_multiplier % 2 != 0) { throw new IllegalArgumentException("The multiplier must be 1 or an even value"); } interval = (int) (DateTime.parseDuration(string_interval) / 1000); if (interval < 1) { throw new IllegalArgumentException("Millisecond intervals are not supported"); } if (interval >= Integer.MAX_VALUE) { throw new IllegalArgumentException("Interval is too big: " + interval); } // The line above will validate for us interval_units = string_interval.charAt(string_interval.length() - 1); int num_span = 0; switch (units) { case 'h': num_span = MAX_SECONDS_IN_HOUR; break; case 'd': num_span = MAX_SECONDS_IN_DAY; break; case 'n': num_span = MAX_SECONDS_IN_MONTH; break; case 'y': num_span = MAX_SECONDS_IN_YEAR; break; default: throw new IllegalArgumentException("Unrecogznied span '" + units + "'"); } num_span *= unit_multiplier; if (interval >= num_span) { throw new IllegalArgumentException("Interval [" + interval + "] is too large for the span [" + units + "]"); } intervals = num_span / (int)interval; if (intervals > MAX_INTERVALS) { throw new IllegalArgumentException("Too many intervals [" + intervals + "] in the span. Must be smaller than [" + MAX_INTERVALS + "] to fit in 14 bits"); } if (intervals < MIN_INTERVALS) { throw new IllegalArgumentException("Not enough intervals [" + intervals + "] for the span. Must be at least [" + MIN_INTERVALS + "]"); } }
[ "void", "validateAndCompile", "(", ")", "{", "if", "(", "temporal_table_name", "==", "null", "||", "temporal_table_name", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The rollup table cannot be null or empty\"", ")", ";", "}", "temporal_table", "=", "temporal_table_name", ".", "getBytes", "(", "Const", ".", "ASCII_CHARSET", ")", ";", "if", "(", "groupby_table_name", "==", "null", "||", "groupby_table_name", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The pre-aggregate rollup table cannot\"", "+", "\" be null or empty\"", ")", ";", "}", "groupby_table", "=", "groupby_table_name", ".", "getBytes", "(", "Const", ".", "ASCII_CHARSET", ")", ";", "if", "(", "units", "!=", "'", "'", "&&", "unit_multiplier", ">", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Multipliers are only usable with the 'h' unit\"", ")", ";", "}", "else", "if", "(", "units", "==", "'", "'", "&&", "unit_multiplier", ">", "1", "&&", "unit_multiplier", "%", "2", "!=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The multiplier must be 1 or an even value\"", ")", ";", "}", "interval", "=", "(", "int", ")", "(", "DateTime", ".", "parseDuration", "(", "string_interval", ")", "/", "1000", ")", ";", "if", "(", "interval", "<", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Millisecond intervals are not supported\"", ")", ";", "}", "if", "(", "interval", ">=", "Integer", ".", "MAX_VALUE", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Interval is too big: \"", "+", "interval", ")", ";", "}", "// The line above will validate for us", "interval_units", "=", "string_interval", ".", "charAt", "(", "string_interval", ".", "length", "(", ")", "-", "1", ")", ";", "int", "num_span", "=", "0", ";", "switch", "(", "units", ")", "{", "case", "'", "'", ":", "num_span", "=", "MAX_SECONDS_IN_HOUR", ";", "break", ";", "case", "'", "'", ":", "num_span", "=", "MAX_SECONDS_IN_DAY", ";", "break", ";", "case", "'", "'", ":", "num_span", "=", "MAX_SECONDS_IN_MONTH", ";", "break", ";", "case", "'", "'", ":", "num_span", "=", "MAX_SECONDS_IN_YEAR", ";", "break", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", "\"Unrecogznied span '\"", "+", "units", "+", "\"'\"", ")", ";", "}", "num_span", "*=", "unit_multiplier", ";", "if", "(", "interval", ">=", "num_span", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Interval [\"", "+", "interval", "+", "\"] is too large for the span [\"", "+", "units", "+", "\"]\"", ")", ";", "}", "intervals", "=", "num_span", "/", "(", "int", ")", "interval", ";", "if", "(", "intervals", ">", "MAX_INTERVALS", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Too many intervals [\"", "+", "intervals", "+", "\"] in the span. Must be smaller than [\"", "+", "MAX_INTERVALS", "+", "\"] to fit in 14 bits\"", ")", ";", "}", "if", "(", "intervals", "<", "MIN_INTERVALS", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Not enough intervals [\"", "+", "intervals", "+", "\"] for the span. Must be at least [\"", "+", "MIN_INTERVALS", "+", "\"]\"", ")", ";", "}", "}" ]
Calculates the number of intervals in a given span for the rollup interval and makes sure we have table names. It also sets the table byte arrays. @return The number of intervals in the span @throws IllegalArgumentException if milliseconds were passed in the interval or the interval couldn't be parsed, the tables are missing, or if the duration is too large, too large for the span or the interval is too large or small for the span or if the span is invalid. @throws NullPointerException if the interval is empty or null
[ "Calculates", "the", "number", "of", "intervals", "in", "a", "given", "span", "for", "the", "rollup", "interval", "and", "makes", "sure", "we", "have", "table", "names", ".", "It", "also", "sets", "the", "table", "byte", "arrays", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/rollup/RollupInterval.java#L169-L232
13,485
OpenTSDB/opentsdb
src/core/AppendDataPoints.java
AppendDataPoints.getBytes
public byte[] getBytes() { final byte[] bytes = new byte[qualifier.length + value.length]; System.arraycopy(this.qualifier, 0, bytes, 0, qualifier.length); System.arraycopy(value, 0, bytes, qualifier.length, value.length); return bytes; }
java
public byte[] getBytes() { final byte[] bytes = new byte[qualifier.length + value.length]; System.arraycopy(this.qualifier, 0, bytes, 0, qualifier.length); System.arraycopy(value, 0, bytes, qualifier.length, value.length); return bytes; }
[ "public", "byte", "[", "]", "getBytes", "(", ")", "{", "final", "byte", "[", "]", "bytes", "=", "new", "byte", "[", "qualifier", ".", "length", "+", "value", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "this", ".", "qualifier", ",", "0", ",", "bytes", ",", "0", ",", "qualifier", ".", "length", ")", ";", "System", ".", "arraycopy", "(", "value", ",", "0", ",", "bytes", ",", "qualifier", ".", "length", ",", "value", ".", "length", ")", ";", "return", "bytes", ";", "}" ]
Concatenates the qualifier and value for appending to a column in the backing data store. @return A byte array to append to the value of a column.
[ "Concatenates", "the", "qualifier", "and", "value", "for", "appending", "to", "a", "column", "in", "the", "backing", "data", "store", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/AppendDataPoints.java#L93-L98
13,486
OpenTSDB/opentsdb
src/tools/CliUtils.java
CliUtils.getMaxMetricID
static long getMaxMetricID(final TSDB tsdb) { // first up, we need the max metric ID so we can split up the data table // amongst threads. final GetRequest get = new GetRequest(tsdb.uidTable(), new byte[] { 0 }); get.family("id".getBytes(CHARSET)); get.qualifier("metrics".getBytes(CHARSET)); ArrayList<KeyValue> row; try { row = tsdb.getClient().get(get).joinUninterruptibly(); if (row == null || row.isEmpty()) { return 0; } final byte[] id_bytes = row.get(0).value(); if (id_bytes.length != 8) { throw new IllegalStateException("Invalid metric max UID, wrong # of bytes"); } return Bytes.getLong(id_bytes); } catch (Exception e) { throw new RuntimeException("Shouldn't be here", e); } }
java
static long getMaxMetricID(final TSDB tsdb) { // first up, we need the max metric ID so we can split up the data table // amongst threads. final GetRequest get = new GetRequest(tsdb.uidTable(), new byte[] { 0 }); get.family("id".getBytes(CHARSET)); get.qualifier("metrics".getBytes(CHARSET)); ArrayList<KeyValue> row; try { row = tsdb.getClient().get(get).joinUninterruptibly(); if (row == null || row.isEmpty()) { return 0; } final byte[] id_bytes = row.get(0).value(); if (id_bytes.length != 8) { throw new IllegalStateException("Invalid metric max UID, wrong # of bytes"); } return Bytes.getLong(id_bytes); } catch (Exception e) { throw new RuntimeException("Shouldn't be here", e); } }
[ "static", "long", "getMaxMetricID", "(", "final", "TSDB", "tsdb", ")", "{", "// first up, we need the max metric ID so we can split up the data table", "// amongst threads.", "final", "GetRequest", "get", "=", "new", "GetRequest", "(", "tsdb", ".", "uidTable", "(", ")", ",", "new", "byte", "[", "]", "{", "0", "}", ")", ";", "get", ".", "family", "(", "\"id\"", ".", "getBytes", "(", "CHARSET", ")", ")", ";", "get", ".", "qualifier", "(", "\"metrics\"", ".", "getBytes", "(", "CHARSET", ")", ")", ";", "ArrayList", "<", "KeyValue", ">", "row", ";", "try", "{", "row", "=", "tsdb", ".", "getClient", "(", ")", ".", "get", "(", "get", ")", ".", "joinUninterruptibly", "(", ")", ";", "if", "(", "row", "==", "null", "||", "row", ".", "isEmpty", "(", ")", ")", "{", "return", "0", ";", "}", "final", "byte", "[", "]", "id_bytes", "=", "row", ".", "get", "(", "0", ")", ".", "value", "(", ")", ";", "if", "(", "id_bytes", ".", "length", "!=", "8", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Invalid metric max UID, wrong # of bytes\"", ")", ";", "}", "return", "Bytes", ".", "getLong", "(", "id_bytes", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Shouldn't be here\"", ",", "e", ")", ";", "}", "}" ]
Returns the max metric ID from the UID table @param tsdb The TSDB to use for data access @return The max metric ID as an integer value, may be 0 if the UID table hasn't been initialized or is missing the UID row or metrics column. @throws IllegalStateException if the UID column can't be found or couldn't be parsed
[ "Returns", "the", "max", "metric", "ID", "from", "the", "UID", "table" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/CliUtils.java#L102-L122
13,487
OpenTSDB/opentsdb
src/tools/CliUtils.java
CliUtils.getDataTableScanner
static final Scanner getDataTableScanner(final TSDB tsdb, final long start_id, final long end_id) throws HBaseException { final short metric_width = TSDB.metrics_width(); final byte[] start_row = Arrays.copyOfRange(Bytes.fromLong(start_id), 8 - metric_width, 8); final byte[] end_row = Arrays.copyOfRange(Bytes.fromLong(end_id), 8 - metric_width, 8); final Scanner scanner = tsdb.getClient().newScanner(tsdb.dataTable()); scanner.setStartKey(start_row); scanner.setStopKey(end_row); scanner.setFamily(TSDB.FAMILY()); return scanner; }
java
static final Scanner getDataTableScanner(final TSDB tsdb, final long start_id, final long end_id) throws HBaseException { final short metric_width = TSDB.metrics_width(); final byte[] start_row = Arrays.copyOfRange(Bytes.fromLong(start_id), 8 - metric_width, 8); final byte[] end_row = Arrays.copyOfRange(Bytes.fromLong(end_id), 8 - metric_width, 8); final Scanner scanner = tsdb.getClient().newScanner(tsdb.dataTable()); scanner.setStartKey(start_row); scanner.setStopKey(end_row); scanner.setFamily(TSDB.FAMILY()); return scanner; }
[ "static", "final", "Scanner", "getDataTableScanner", "(", "final", "TSDB", "tsdb", ",", "final", "long", "start_id", ",", "final", "long", "end_id", ")", "throws", "HBaseException", "{", "final", "short", "metric_width", "=", "TSDB", ".", "metrics_width", "(", ")", ";", "final", "byte", "[", "]", "start_row", "=", "Arrays", ".", "copyOfRange", "(", "Bytes", ".", "fromLong", "(", "start_id", ")", ",", "8", "-", "metric_width", ",", "8", ")", ";", "final", "byte", "[", "]", "end_row", "=", "Arrays", ".", "copyOfRange", "(", "Bytes", ".", "fromLong", "(", "end_id", ")", ",", "8", "-", "metric_width", ",", "8", ")", ";", "final", "Scanner", "scanner", "=", "tsdb", ".", "getClient", "(", ")", ".", "newScanner", "(", "tsdb", ".", "dataTable", "(", ")", ")", ";", "scanner", ".", "setStartKey", "(", "start_row", ")", ";", "scanner", ".", "setStopKey", "(", "end_row", ")", ";", "scanner", ".", "setFamily", "(", "TSDB", ".", "FAMILY", "(", ")", ")", ";", "return", "scanner", ";", "}" ]
Returns a scanner set to iterate over a range of metrics in the main tsdb-data table. @param tsdb The TSDB to use for data access @param start_id A metric ID to start scanning on @param end_id A metric ID to end scanning on @return A scanner on the "t" CF configured for the specified range @throws HBaseException if something goes pear shaped
[ "Returns", "a", "scanner", "set", "to", "iterate", "over", "a", "range", "of", "metrics", "in", "the", "main", "tsdb", "-", "data", "table", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/CliUtils.java#L133-L146
13,488
OpenTSDB/opentsdb
src/tsd/client/MetricForm.java
MetricForm.getFilters
private List<Filter> getFilters(final boolean group_by) { final int ntags = getNumTags(); final List<Filter> filters = new ArrayList<Filter>(ntags); for (int tag = 0; tag < ntags; tag++) { final Filter filter = new Filter(); filter.tagk = getTagName(tag); filter.tagv = getTagValue(tag); filter.is_groupby = isTagGroupby(tag); if (filter.tagk.isEmpty() || filter.tagv.isEmpty()) { continue; } if (filter.is_groupby == group_by) { filters.add(filter); } } // sort on the tagk Collections.sort(filters); return filters; }
java
private List<Filter> getFilters(final boolean group_by) { final int ntags = getNumTags(); final List<Filter> filters = new ArrayList<Filter>(ntags); for (int tag = 0; tag < ntags; tag++) { final Filter filter = new Filter(); filter.tagk = getTagName(tag); filter.tagv = getTagValue(tag); filter.is_groupby = isTagGroupby(tag); if (filter.tagk.isEmpty() || filter.tagv.isEmpty()) { continue; } if (filter.is_groupby == group_by) { filters.add(filter); } } // sort on the tagk Collections.sort(filters); return filters; }
[ "private", "List", "<", "Filter", ">", "getFilters", "(", "final", "boolean", "group_by", ")", "{", "final", "int", "ntags", "=", "getNumTags", "(", ")", ";", "final", "List", "<", "Filter", ">", "filters", "=", "new", "ArrayList", "<", "Filter", ">", "(", "ntags", ")", ";", "for", "(", "int", "tag", "=", "0", ";", "tag", "<", "ntags", ";", "tag", "++", ")", "{", "final", "Filter", "filter", "=", "new", "Filter", "(", ")", ";", "filter", ".", "tagk", "=", "getTagName", "(", "tag", ")", ";", "filter", ".", "tagv", "=", "getTagValue", "(", "tag", ")", ";", "filter", ".", "is_groupby", "=", "isTagGroupby", "(", "tag", ")", ";", "if", "(", "filter", ".", "tagk", ".", "isEmpty", "(", ")", "||", "filter", ".", "tagv", ".", "isEmpty", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "filter", ".", "is_groupby", "==", "group_by", ")", "{", "filters", ".", "add", "(", "filter", ")", ";", "}", "}", "// sort on the tagk", "Collections", ".", "sort", "(", "filters", ")", ";", "return", "filters", ";", "}" ]
Helper method to extract the tags from the row set and sort them before sending to the API so that we avoid a bug wherein the sort order changes on reload. @param group_by Whether or not to fetch group by or non-group by filters. @return A non-null list of filters. May be empty.
[ "Helper", "method", "to", "extract", "the", "tags", "from", "the", "row", "set", "and", "sort", "them", "before", "sending", "to", "the", "API", "so", "that", "we", "avoid", "a", "bug", "wherein", "the", "sort", "order", "changes", "on", "reload", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/MetricForm.java#L467-L485
13,489
OpenTSDB/opentsdb
src/tsd/client/MetricForm.java
MetricForm.setSelectedItem
private void setSelectedItem(final ListBox list, final String item) { final int nitems = list.getItemCount(); for (int i = 0; i < nitems; i++) { if (item.equals(list.getValue(i))) { list.setSelectedIndex(i); return; } } }
java
private void setSelectedItem(final ListBox list, final String item) { final int nitems = list.getItemCount(); for (int i = 0; i < nitems; i++) { if (item.equals(list.getValue(i))) { list.setSelectedIndex(i); return; } } }
[ "private", "void", "setSelectedItem", "(", "final", "ListBox", "list", ",", "final", "String", "item", ")", "{", "final", "int", "nitems", "=", "list", ".", "getItemCount", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nitems", ";", "i", "++", ")", "{", "if", "(", "item", ".", "equals", "(", "list", ".", "getValue", "(", "i", ")", ")", ")", "{", "list", ".", "setSelectedIndex", "(", "i", ")", ";", "return", ";", "}", "}", "}" ]
If the given item is in the list, mark it as selected. @param list The list to manipulate. @param item The item to select if present.
[ "If", "the", "given", "item", "is", "in", "the", "list", "mark", "it", "as", "selected", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/MetricForm.java#L689-L697
13,490
OpenTSDB/opentsdb
src/utils/Threads.java
Threads.newTimer
public static HashedWheelTimer newTimer(final int ticks, final int ticks_per_wheel, final String name) { class TimerThreadNamer implements ThreadNameDeterminer { @Override public String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception { return "OpenTSDB Timer " + name + " #" + TIMER_ID.incrementAndGet(); } } return new HashedWheelTimer(Executors.defaultThreadFactory(), new TimerThreadNamer(), ticks, MILLISECONDS, ticks_per_wheel); }
java
public static HashedWheelTimer newTimer(final int ticks, final int ticks_per_wheel, final String name) { class TimerThreadNamer implements ThreadNameDeterminer { @Override public String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception { return "OpenTSDB Timer " + name + " #" + TIMER_ID.incrementAndGet(); } } return new HashedWheelTimer(Executors.defaultThreadFactory(), new TimerThreadNamer(), ticks, MILLISECONDS, ticks_per_wheel); }
[ "public", "static", "HashedWheelTimer", "newTimer", "(", "final", "int", "ticks", ",", "final", "int", "ticks_per_wheel", ",", "final", "String", "name", ")", "{", "class", "TimerThreadNamer", "implements", "ThreadNameDeterminer", "{", "@", "Override", "public", "String", "determineThreadName", "(", "String", "currentThreadName", ",", "String", "proposedThreadName", ")", "throws", "Exception", "{", "return", "\"OpenTSDB Timer \"", "+", "name", "+", "\" #\"", "+", "TIMER_ID", ".", "incrementAndGet", "(", ")", ";", "}", "}", "return", "new", "HashedWheelTimer", "(", "Executors", ".", "defaultThreadFactory", "(", ")", ",", "new", "TimerThreadNamer", "(", ")", ",", "ticks", ",", "MILLISECONDS", ",", "ticks_per_wheel", ")", ";", "}" ]
Returns a new HashedWheelTimer with a name and default ticks @param ticks How many ticks per second to sleep between executions, in ms @param ticks_per_wheel The size of the wheel @param name The name to add to the thread name @return A timer
[ "Returns", "a", "new", "HashedWheelTimer", "with", "a", "name", "and", "default", "ticks" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Threads.java#L85-L96
13,491
OpenTSDB/opentsdb
src/query/pojo/Downsampler.java
Downsampler.validate
public void validate() { if (interval == null || interval.isEmpty()) { throw new IllegalArgumentException("Missing or empty interval"); } DateTime.parseDuration(interval); if (aggregator == null || aggregator.isEmpty()) { throw new IllegalArgumentException("Missing or empty aggregator"); } try { Aggregators.get(aggregator.toLowerCase()); } catch (final NoSuchElementException e) { throw new IllegalArgumentException("Invalid aggregator"); } if (fill_policy != null) { fill_policy.validate(); } }
java
public void validate() { if (interval == null || interval.isEmpty()) { throw new IllegalArgumentException("Missing or empty interval"); } DateTime.parseDuration(interval); if (aggregator == null || aggregator.isEmpty()) { throw new IllegalArgumentException("Missing or empty aggregator"); } try { Aggregators.get(aggregator.toLowerCase()); } catch (final NoSuchElementException e) { throw new IllegalArgumentException("Invalid aggregator"); } if (fill_policy != null) { fill_policy.validate(); } }
[ "public", "void", "validate", "(", ")", "{", "if", "(", "interval", "==", "null", "||", "interval", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Missing or empty interval\"", ")", ";", "}", "DateTime", ".", "parseDuration", "(", "interval", ")", ";", "if", "(", "aggregator", "==", "null", "||", "aggregator", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Missing or empty aggregator\"", ")", ";", "}", "try", "{", "Aggregators", ".", "get", "(", "aggregator", ".", "toLowerCase", "(", ")", ")", ";", "}", "catch", "(", "final", "NoSuchElementException", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid aggregator\"", ")", ";", "}", "if", "(", "fill_policy", "!=", "null", ")", "{", "fill_policy", ".", "validate", "(", ")", ";", "}", "}" ]
Validates the downsampler @throws IllegalArgumentException if one or more parameters were invalid
[ "Validates", "the", "downsampler" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/pojo/Downsampler.java#L60-L78
13,492
OpenTSDB/opentsdb
src/query/expression/NumericFillPolicy.java
NumericFillPolicy.validate
public void validate() { if (policy == null) { if (value == 0) { policy = FillPolicy.ZERO; } else if (Double.isNaN(value)) { policy = FillPolicy.NOT_A_NUMBER; } else { policy = FillPolicy.SCALAR; } } else { switch (policy) { case NONE: case NOT_A_NUMBER: if (value != 0 && !Double.isNaN(value)) { throw new IllegalArgumentException( "The value for NONE and NAN must be NaN"); } value = Double.NaN; break; case ZERO: if (value != 0) { throw new IllegalArgumentException("The value for ZERO must be 0"); } value = 0; break; case NULL: if (value != 0 && !Double.isNaN(value)) { throw new IllegalArgumentException("The value for NULL must be 0"); } value = Double.NaN; break; case SCALAR: // it CAN be zero break; } } }
java
public void validate() { if (policy == null) { if (value == 0) { policy = FillPolicy.ZERO; } else if (Double.isNaN(value)) { policy = FillPolicy.NOT_A_NUMBER; } else { policy = FillPolicy.SCALAR; } } else { switch (policy) { case NONE: case NOT_A_NUMBER: if (value != 0 && !Double.isNaN(value)) { throw new IllegalArgumentException( "The value for NONE and NAN must be NaN"); } value = Double.NaN; break; case ZERO: if (value != 0) { throw new IllegalArgumentException("The value for ZERO must be 0"); } value = 0; break; case NULL: if (value != 0 && !Double.isNaN(value)) { throw new IllegalArgumentException("The value for NULL must be 0"); } value = Double.NaN; break; case SCALAR: // it CAN be zero break; } } }
[ "public", "void", "validate", "(", ")", "{", "if", "(", "policy", "==", "null", ")", "{", "if", "(", "value", "==", "0", ")", "{", "policy", "=", "FillPolicy", ".", "ZERO", ";", "}", "else", "if", "(", "Double", ".", "isNaN", "(", "value", ")", ")", "{", "policy", "=", "FillPolicy", ".", "NOT_A_NUMBER", ";", "}", "else", "{", "policy", "=", "FillPolicy", ".", "SCALAR", ";", "}", "}", "else", "{", "switch", "(", "policy", ")", "{", "case", "NONE", ":", "case", "NOT_A_NUMBER", ":", "if", "(", "value", "!=", "0", "&&", "!", "Double", ".", "isNaN", "(", "value", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The value for NONE and NAN must be NaN\"", ")", ";", "}", "value", "=", "Double", ".", "NaN", ";", "break", ";", "case", "ZERO", ":", "if", "(", "value", "!=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The value for ZERO must be 0\"", ")", ";", "}", "value", "=", "0", ";", "break", ";", "case", "NULL", ":", "if", "(", "value", "!=", "0", "&&", "!", "Double", ".", "isNaN", "(", "value", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The value for NULL must be 0\"", ")", ";", "}", "value", "=", "Double", ".", "NaN", ";", "break", ";", "case", "SCALAR", ":", "// it CAN be zero", "break", ";", "}", "}", "}" ]
Makes sure the policy name and value are a suitable combination. If one or the other is missing then we set the other with the proper value. @throws IllegalArgumentException if the combination is bad
[ "Makes", "sure", "the", "policy", "name", "and", "value", "are", "a", "suitable", "combination", ".", "If", "one", "or", "the", "other", "is", "missing", "then", "we", "set", "the", "other", "with", "the", "proper", "value", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/NumericFillPolicy.java#L140-L175
13,493
OpenTSDB/opentsdb
src/core/HistogramCodecManager.java
HistogramCodecManager.getCodec
public HistogramDataPointCodec getCodec(final int id) { final HistogramDataPointCodec codec = codecs.get(id); if (codec == null) { throw new IllegalArgumentException("No codec found mapped to ID " + id); } return codec; }
java
public HistogramDataPointCodec getCodec(final int id) { final HistogramDataPointCodec codec = codecs.get(id); if (codec == null) { throw new IllegalArgumentException("No codec found mapped to ID " + id); } return codec; }
[ "public", "HistogramDataPointCodec", "getCodec", "(", "final", "int", "id", ")", "{", "final", "HistogramDataPointCodec", "codec", "=", "codecs", ".", "get", "(", "id", ")", ";", "if", "(", "codec", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"No codec found mapped to ID \"", "+", "id", ")", ";", "}", "return", "codec", ";", "}" ]
Return the instance of the given codec. @param id The numeric ID of the codec (the first byte in storage). @return The instance of the given codec @throws IllegalArgumentException if no codec was found for the given ID.
[ "Return", "the", "instance", "of", "the", "given", "codec", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/HistogramCodecManager.java#L148-L154
13,494
OpenTSDB/opentsdb
src/core/HistogramCodecManager.java
HistogramCodecManager.getCodec
public int getCodec(final Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("Clazz cannot be null."); } final Integer id = codecs_ids.get(clazz); if (id == null) { throw new IllegalArgumentException("No codec ID assigned to class " + clazz); } return id; }
java
public int getCodec(final Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("Clazz cannot be null."); } final Integer id = codecs_ids.get(clazz); if (id == null) { throw new IllegalArgumentException("No codec ID assigned to class " + clazz); } return id; }
[ "public", "int", "getCodec", "(", "final", "Class", "<", "?", ">", "clazz", ")", "{", "if", "(", "clazz", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Clazz cannot be null.\"", ")", ";", "}", "final", "Integer", "id", "=", "codecs_ids", ".", "get", "(", "clazz", ")", ";", "if", "(", "id", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"No codec ID assigned to class \"", "+", "clazz", ")", ";", "}", "return", "id", ";", "}" ]
Return the ID of the given codec. @param clazz The non-null class to search for. @return The ID of the codec. @throws IllegalArgumentException if the class was null or no ID was assigned to the class.
[ "Return", "the", "ID", "of", "the", "given", "codec", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/HistogramCodecManager.java#L163-L173
13,495
OpenTSDB/opentsdb
src/core/HistogramCodecManager.java
HistogramCodecManager.encode
public byte[] encode(final int id, final Histogram data_point, final boolean include_id) { final HistogramDataPointCodec codec = getCodec(id); return codec.encode(data_point, include_id); }
java
public byte[] encode(final int id, final Histogram data_point, final boolean include_id) { final HistogramDataPointCodec codec = getCodec(id); return codec.encode(data_point, include_id); }
[ "public", "byte", "[", "]", "encode", "(", "final", "int", "id", ",", "final", "Histogram", "data_point", ",", "final", "boolean", "include_id", ")", "{", "final", "HistogramDataPointCodec", "codec", "=", "getCodec", "(", "id", ")", ";", "return", "codec", ".", "encode", "(", "data_point", ",", "include_id", ")", ";", "}" ]
Finds the proper codec and calls it's encode method to create a byte array with the given ID as the first byte. @param id The ID of the histogram type to search for. @param data_point The non-null data point to encode. @param include_id Whether or not to include the ID prefix when encoding. @return A non-null and non-empty byte array if the codec was found. @throws IllegalArgumentException if no codec was found for the given ID or the histogram may have been of the wrong type or failed encoding.
[ "Finds", "the", "proper", "codec", "and", "calls", "it", "s", "encode", "method", "to", "create", "a", "byte", "array", "with", "the", "given", "ID", "as", "the", "first", "byte", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/HistogramCodecManager.java#L185-L190
13,496
OpenTSDB/opentsdb
src/core/HistogramCodecManager.java
HistogramCodecManager.decode
public Histogram decode(final int id, final byte[] raw_data, final boolean includes_id) { final HistogramDataPointCodec codec = getCodec(id); return codec.decode(raw_data, includes_id); }
java
public Histogram decode(final int id, final byte[] raw_data, final boolean includes_id) { final HistogramDataPointCodec codec = getCodec(id); return codec.decode(raw_data, includes_id); }
[ "public", "Histogram", "decode", "(", "final", "int", "id", ",", "final", "byte", "[", "]", "raw_data", ",", "final", "boolean", "includes_id", ")", "{", "final", "HistogramDataPointCodec", "codec", "=", "getCodec", "(", "id", ")", ";", "return", "codec", ".", "decode", "(", "raw_data", ",", "includes_id", ")", ";", "}" ]
Finds the proper codec and calls it's decode method to return the histogram data point for queries or validation. @param id The ID of the histogram type to search for. @param raw_data The non-null and non-empty byte array to parse. Should NOT include the first byte of the ID in the data. @param includes_id Whether or not the data includes the ID prefix. @return A non-null data point if decoding was successful.
[ "Finds", "the", "proper", "codec", "and", "calls", "it", "s", "decode", "method", "to", "return", "the", "histogram", "data", "point", "for", "queries", "or", "validation", "." ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/HistogramCodecManager.java#L201-L206
13,497
OpenTSDB/opentsdb
src/tsd/StatsRpc.java
StatsRpc.execute
public Deferred<Object> execute(final TSDB tsdb, final Channel chan, final String[] cmd) { final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical"); final StringBuilder buf = new StringBuilder(1024); final ASCIICollector collector = new ASCIICollector("tsd", buf, null); doCollectStats(tsdb, collector, canonical); chan.write(buf.toString()); return Deferred.fromResult(null); }
java
public Deferred<Object> execute(final TSDB tsdb, final Channel chan, final String[] cmd) { final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical"); final StringBuilder buf = new StringBuilder(1024); final ASCIICollector collector = new ASCIICollector("tsd", buf, null); doCollectStats(tsdb, collector, canonical); chan.write(buf.toString()); return Deferred.fromResult(null); }
[ "public", "Deferred", "<", "Object", ">", "execute", "(", "final", "TSDB", "tsdb", ",", "final", "Channel", "chan", ",", "final", "String", "[", "]", "cmd", ")", "{", "final", "boolean", "canonical", "=", "tsdb", ".", "getConfig", "(", ")", ".", "getBoolean", "(", "\"tsd.stats.canonical\"", ")", ";", "final", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "1024", ")", ";", "final", "ASCIICollector", "collector", "=", "new", "ASCIICollector", "(", "\"tsd\"", ",", "buf", ",", "null", ")", ";", "doCollectStats", "(", "tsdb", ",", "collector", ",", "canonical", ")", ";", "chan", ".", "write", "(", "buf", ".", "toString", "(", ")", ")", ";", "return", "Deferred", ".", "fromResult", "(", "null", ")", ";", "}" ]
Telnet RPC responder that returns the stats in ASCII style @param tsdb The TSDB to use for fetching stats @param chan The netty channel to respond on @param cmd call parameters
[ "Telnet", "RPC", "responder", "that", "returns", "the", "stats", "in", "ASCII", "style" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/StatsRpc.java#L59-L67
13,498
OpenTSDB/opentsdb
src/tsd/StatsRpc.java
StatsRpc.execute
public void execute(final TSDB tsdb, final HttpQuery query) { // only accept GET/POST if (query.method() != HttpMethod.GET && query.method() != HttpMethod.POST) { throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, "Method not allowed", "The HTTP method [" + query.method().getName() + "] is not permitted for this endpoint"); } try { final String[] uri = query.explodeAPIPath(); final String endpoint = uri.length > 1 ? uri[1].toLowerCase() : ""; // Handle /threads and /regions. if ("threads".equals(endpoint)) { printThreadStats(query); return; } else if ("jvm".equals(endpoint)) { printJVMStats(tsdb, query); return; } else if ("query".equals(endpoint)) { printQueryStats(query); return; } else if ("region_clients".equals(endpoint)) { printRegionClientStats(tsdb, query); return; } } catch (IllegalArgumentException e) { // this is thrown if the url doesn't start with /api. To maintain backwards // compatibility with the /stats endpoint we can catch and continue here. } final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical"); // if we don't have an API request we need to respond with the 1.x version if (query.apiVersion() < 1) { final boolean json = query.hasQueryStringParam("json"); final StringBuilder buf = json ? null : new StringBuilder(2048); final ArrayList<String> stats = json ? new ArrayList<String>(64) : null; final ASCIICollector collector = new ASCIICollector("tsd", buf, stats); doCollectStats(tsdb, collector, canonical); if (json) { query.sendReply(JSON.serializeToBytes(stats)); } else { query.sendReply(buf); } return; } // we have an API version, so go newschool final List<IncomingDataPoint> dps = new ArrayList<IncomingDataPoint>(64); final SerializerCollector collector = new SerializerCollector("tsd", dps, canonical); ConnectionManager.collectStats(collector); RpcHandler.collectStats(collector); RpcManager.collectStats(collector); tsdb.collectStats(collector); query.sendReply(query.serializer().formatStatsV1(dps)); }
java
public void execute(final TSDB tsdb, final HttpQuery query) { // only accept GET/POST if (query.method() != HttpMethod.GET && query.method() != HttpMethod.POST) { throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, "Method not allowed", "The HTTP method [" + query.method().getName() + "] is not permitted for this endpoint"); } try { final String[] uri = query.explodeAPIPath(); final String endpoint = uri.length > 1 ? uri[1].toLowerCase() : ""; // Handle /threads and /regions. if ("threads".equals(endpoint)) { printThreadStats(query); return; } else if ("jvm".equals(endpoint)) { printJVMStats(tsdb, query); return; } else if ("query".equals(endpoint)) { printQueryStats(query); return; } else if ("region_clients".equals(endpoint)) { printRegionClientStats(tsdb, query); return; } } catch (IllegalArgumentException e) { // this is thrown if the url doesn't start with /api. To maintain backwards // compatibility with the /stats endpoint we can catch and continue here. } final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical"); // if we don't have an API request we need to respond with the 1.x version if (query.apiVersion() < 1) { final boolean json = query.hasQueryStringParam("json"); final StringBuilder buf = json ? null : new StringBuilder(2048); final ArrayList<String> stats = json ? new ArrayList<String>(64) : null; final ASCIICollector collector = new ASCIICollector("tsd", buf, stats); doCollectStats(tsdb, collector, canonical); if (json) { query.sendReply(JSON.serializeToBytes(stats)); } else { query.sendReply(buf); } return; } // we have an API version, so go newschool final List<IncomingDataPoint> dps = new ArrayList<IncomingDataPoint>(64); final SerializerCollector collector = new SerializerCollector("tsd", dps, canonical); ConnectionManager.collectStats(collector); RpcHandler.collectStats(collector); RpcManager.collectStats(collector); tsdb.collectStats(collector); query.sendReply(query.serializer().formatStatsV1(dps)); }
[ "public", "void", "execute", "(", "final", "TSDB", "tsdb", ",", "final", "HttpQuery", "query", ")", "{", "// only accept GET/POST", "if", "(", "query", ".", "method", "(", ")", "!=", "HttpMethod", ".", "GET", "&&", "query", ".", "method", "(", ")", "!=", "HttpMethod", ".", "POST", ")", "{", "throw", "new", "BadRequestException", "(", "HttpResponseStatus", ".", "METHOD_NOT_ALLOWED", ",", "\"Method not allowed\"", ",", "\"The HTTP method [\"", "+", "query", ".", "method", "(", ")", ".", "getName", "(", ")", "+", "\"] is not permitted for this endpoint\"", ")", ";", "}", "try", "{", "final", "String", "[", "]", "uri", "=", "query", ".", "explodeAPIPath", "(", ")", ";", "final", "String", "endpoint", "=", "uri", ".", "length", ">", "1", "?", "uri", "[", "1", "]", ".", "toLowerCase", "(", ")", ":", "\"\"", ";", "// Handle /threads and /regions.", "if", "(", "\"threads\"", ".", "equals", "(", "endpoint", ")", ")", "{", "printThreadStats", "(", "query", ")", ";", "return", ";", "}", "else", "if", "(", "\"jvm\"", ".", "equals", "(", "endpoint", ")", ")", "{", "printJVMStats", "(", "tsdb", ",", "query", ")", ";", "return", ";", "}", "else", "if", "(", "\"query\"", ".", "equals", "(", "endpoint", ")", ")", "{", "printQueryStats", "(", "query", ")", ";", "return", ";", "}", "else", "if", "(", "\"region_clients\"", ".", "equals", "(", "endpoint", ")", ")", "{", "printRegionClientStats", "(", "tsdb", ",", "query", ")", ";", "return", ";", "}", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "// this is thrown if the url doesn't start with /api. To maintain backwards", "// compatibility with the /stats endpoint we can catch and continue here.", "}", "final", "boolean", "canonical", "=", "tsdb", ".", "getConfig", "(", ")", ".", "getBoolean", "(", "\"tsd.stats.canonical\"", ")", ";", "// if we don't have an API request we need to respond with the 1.x version", "if", "(", "query", ".", "apiVersion", "(", ")", "<", "1", ")", "{", "final", "boolean", "json", "=", "query", ".", "hasQueryStringParam", "(", "\"json\"", ")", ";", "final", "StringBuilder", "buf", "=", "json", "?", "null", ":", "new", "StringBuilder", "(", "2048", ")", ";", "final", "ArrayList", "<", "String", ">", "stats", "=", "json", "?", "new", "ArrayList", "<", "String", ">", "(", "64", ")", ":", "null", ";", "final", "ASCIICollector", "collector", "=", "new", "ASCIICollector", "(", "\"tsd\"", ",", "buf", ",", "stats", ")", ";", "doCollectStats", "(", "tsdb", ",", "collector", ",", "canonical", ")", ";", "if", "(", "json", ")", "{", "query", ".", "sendReply", "(", "JSON", ".", "serializeToBytes", "(", "stats", ")", ")", ";", "}", "else", "{", "query", ".", "sendReply", "(", "buf", ")", ";", "}", "return", ";", "}", "// we have an API version, so go newschool", "final", "List", "<", "IncomingDataPoint", ">", "dps", "=", "new", "ArrayList", "<", "IncomingDataPoint", ">", "(", "64", ")", ";", "final", "SerializerCollector", "collector", "=", "new", "SerializerCollector", "(", "\"tsd\"", ",", "dps", ",", "canonical", ")", ";", "ConnectionManager", ".", "collectStats", "(", "collector", ")", ";", "RpcHandler", ".", "collectStats", "(", "collector", ")", ";", "RpcManager", ".", "collectStats", "(", "collector", ")", ";", "tsdb", ".", "collectStats", "(", "collector", ")", ";", "query", ".", "sendReply", "(", "query", ".", "serializer", "(", ")", ".", "formatStatsV1", "(", "dps", ")", ")", ";", "}" ]
HTTP resposne handler @param tsdb The TSDB to which we belong @param query The query to parse and respond to
[ "HTTP", "resposne", "handler" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/StatsRpc.java#L74-L131
13,499
OpenTSDB/opentsdb
src/tsd/StatsRpc.java
StatsRpc.doCollectStats
private void doCollectStats(final TSDB tsdb, final StatsCollector collector, final boolean canonical) { collector.addHostTag(canonical); ConnectionManager.collectStats(collector); RpcHandler.collectStats(collector); RpcManager.collectStats(collector); collectThreadStats(collector); tsdb.collectStats(collector); }
java
private void doCollectStats(final TSDB tsdb, final StatsCollector collector, final boolean canonical) { collector.addHostTag(canonical); ConnectionManager.collectStats(collector); RpcHandler.collectStats(collector); RpcManager.collectStats(collector); collectThreadStats(collector); tsdb.collectStats(collector); }
[ "private", "void", "doCollectStats", "(", "final", "TSDB", "tsdb", ",", "final", "StatsCollector", "collector", ",", "final", "boolean", "canonical", ")", "{", "collector", ".", "addHostTag", "(", "canonical", ")", ";", "ConnectionManager", ".", "collectStats", "(", "collector", ")", ";", "RpcHandler", ".", "collectStats", "(", "collector", ")", ";", "RpcManager", ".", "collectStats", "(", "collector", ")", ";", "collectThreadStats", "(", "collector", ")", ";", "tsdb", ".", "collectStats", "(", "collector", ")", ";", "}" ]
Helper to record the statistics for the current TSD @param tsdb The TSDB to use for fetching stats @param collector The collector class to call for emitting stats
[ "Helper", "to", "record", "the", "statistics", "for", "the", "current", "TSD" ]
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/StatsRpc.java#L138-L146