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,700
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.getTagsFromTSUID
|
public static List<byte[]> getTagsFromTSUID(final String tsuid) {
if (tsuid == null || tsuid.isEmpty()) {
throw new IllegalArgumentException("Missing TSUID");
}
if (tsuid.length() <= TSDB.metrics_width() * 2) {
throw new IllegalArgumentException(
"TSUID is too short, may be missing tags");
}
final List<byte[]> tags = new ArrayList<byte[]>();
final int pair_width = (TSDB.tagk_width() * 2) + (TSDB.tagv_width() * 2);
// start after the metric then iterate over each tagk/tagv pair
for (int i = TSDB.metrics_width() * 2; i < tsuid.length(); i+= pair_width) {
if (i + pair_width > tsuid.length()){
throw new IllegalArgumentException(
"The TSUID appears to be malformed, improper tag width");
}
String tag = tsuid.substring(i, i + (TSDB.tagk_width() * 2));
tags.add(UniqueId.stringToUid(tag));
tag = tsuid.substring(i + (TSDB.tagk_width() * 2), i + pair_width);
tags.add(UniqueId.stringToUid(tag));
}
return tags;
}
|
java
|
public static List<byte[]> getTagsFromTSUID(final String tsuid) {
if (tsuid == null || tsuid.isEmpty()) {
throw new IllegalArgumentException("Missing TSUID");
}
if (tsuid.length() <= TSDB.metrics_width() * 2) {
throw new IllegalArgumentException(
"TSUID is too short, may be missing tags");
}
final List<byte[]> tags = new ArrayList<byte[]>();
final int pair_width = (TSDB.tagk_width() * 2) + (TSDB.tagv_width() * 2);
// start after the metric then iterate over each tagk/tagv pair
for (int i = TSDB.metrics_width() * 2; i < tsuid.length(); i+= pair_width) {
if (i + pair_width > tsuid.length()){
throw new IllegalArgumentException(
"The TSUID appears to be malformed, improper tag width");
}
String tag = tsuid.substring(i, i + (TSDB.tagk_width() * 2));
tags.add(UniqueId.stringToUid(tag));
tag = tsuid.substring(i + (TSDB.tagk_width() * 2), i + pair_width);
tags.add(UniqueId.stringToUid(tag));
}
return tags;
}
|
[
"public",
"static",
"List",
"<",
"byte",
"[",
"]",
">",
"getTagsFromTSUID",
"(",
"final",
"String",
"tsuid",
")",
"{",
"if",
"(",
"tsuid",
"==",
"null",
"||",
"tsuid",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Missing TSUID\"",
")",
";",
"}",
"if",
"(",
"tsuid",
".",
"length",
"(",
")",
"<=",
"TSDB",
".",
"metrics_width",
"(",
")",
"*",
"2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"TSUID is too short, may be missing tags\"",
")",
";",
"}",
"final",
"List",
"<",
"byte",
"[",
"]",
">",
"tags",
"=",
"new",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
"(",
")",
";",
"final",
"int",
"pair_width",
"=",
"(",
"TSDB",
".",
"tagk_width",
"(",
")",
"*",
"2",
")",
"+",
"(",
"TSDB",
".",
"tagv_width",
"(",
")",
"*",
"2",
")",
";",
"// start after the metric then iterate over each tagk/tagv pair",
"for",
"(",
"int",
"i",
"=",
"TSDB",
".",
"metrics_width",
"(",
")",
"*",
"2",
";",
"i",
"<",
"tsuid",
".",
"length",
"(",
")",
";",
"i",
"+=",
"pair_width",
")",
"{",
"if",
"(",
"i",
"+",
"pair_width",
">",
"tsuid",
".",
"length",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The TSUID appears to be malformed, improper tag width\"",
")",
";",
"}",
"String",
"tag",
"=",
"tsuid",
".",
"substring",
"(",
"i",
",",
"i",
"+",
"(",
"TSDB",
".",
"tagk_width",
"(",
")",
"*",
"2",
")",
")",
";",
"tags",
".",
"add",
"(",
"UniqueId",
".",
"stringToUid",
"(",
"tag",
")",
")",
";",
"tag",
"=",
"tsuid",
".",
"substring",
"(",
"i",
"+",
"(",
"TSDB",
".",
"tagk_width",
"(",
")",
"*",
"2",
")",
",",
"i",
"+",
"pair_width",
")",
";",
"tags",
".",
"add",
"(",
"UniqueId",
".",
"stringToUid",
"(",
"tag",
")",
")",
";",
"}",
"return",
"tags",
";",
"}"
] |
Extracts a list of tagks and tagvs as individual values in a list
@param tsuid The tsuid to parse
@return A list of tagk/tagv UIDs alternating with tagk, tagv, tagk, tagv
@throws IllegalArgumentException if the TSUID is malformed
@since 2.1
|
[
"Extracts",
"a",
"list",
"of",
"tagks",
"and",
"tagvs",
"as",
"individual",
"values",
"in",
"a",
"list"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1605-L1629
|
13,701
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.getUsedUIDs
|
public static Deferred<Map<String, Long>> getUsedUIDs(final TSDB tsdb,
final byte[][] kinds) {
/**
* Returns a map with 0 if the max ID row hasn't been initialized yet,
* otherwise the map has actual data
*/
final class GetCB implements Callback<Map<String, Long>,
ArrayList<KeyValue>> {
@Override
public Map<String, Long> call(final ArrayList<KeyValue> row)
throws Exception {
final Map<String, Long> results = new HashMap<String, Long>(3);
if (row == null || row.isEmpty()) {
// it could be the case that this is the first time the TSD has run
// and the user hasn't put any metrics in, so log and return 0s
LOG.info("Could not find the UID assignment row");
for (final byte[] kind : kinds) {
results.put(new String(kind, CHARSET), 0L);
}
return results;
}
for (final KeyValue column : row) {
results.put(new String(column.qualifier(), CHARSET),
Bytes.getLong(column.value()));
}
// if the user is starting with a fresh UID table, we need to account
// for missing columns
for (final byte[] kind : kinds) {
if (results.get(new String(kind, CHARSET)) == null) {
results.put(new String(kind, CHARSET), 0L);
}
}
return results;
}
}
final GetRequest get = new GetRequest(tsdb.uidTable(), MAXID_ROW);
get.family(ID_FAMILY);
get.qualifiers(kinds);
return tsdb.getClient().get(get).addCallback(new GetCB());
}
|
java
|
public static Deferred<Map<String, Long>> getUsedUIDs(final TSDB tsdb,
final byte[][] kinds) {
/**
* Returns a map with 0 if the max ID row hasn't been initialized yet,
* otherwise the map has actual data
*/
final class GetCB implements Callback<Map<String, Long>,
ArrayList<KeyValue>> {
@Override
public Map<String, Long> call(final ArrayList<KeyValue> row)
throws Exception {
final Map<String, Long> results = new HashMap<String, Long>(3);
if (row == null || row.isEmpty()) {
// it could be the case that this is the first time the TSD has run
// and the user hasn't put any metrics in, so log and return 0s
LOG.info("Could not find the UID assignment row");
for (final byte[] kind : kinds) {
results.put(new String(kind, CHARSET), 0L);
}
return results;
}
for (final KeyValue column : row) {
results.put(new String(column.qualifier(), CHARSET),
Bytes.getLong(column.value()));
}
// if the user is starting with a fresh UID table, we need to account
// for missing columns
for (final byte[] kind : kinds) {
if (results.get(new String(kind, CHARSET)) == null) {
results.put(new String(kind, CHARSET), 0L);
}
}
return results;
}
}
final GetRequest get = new GetRequest(tsdb.uidTable(), MAXID_ROW);
get.family(ID_FAMILY);
get.qualifiers(kinds);
return tsdb.getClient().get(get).addCallback(new GetCB());
}
|
[
"public",
"static",
"Deferred",
"<",
"Map",
"<",
"String",
",",
"Long",
">",
">",
"getUsedUIDs",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"byte",
"[",
"]",
"[",
"]",
"kinds",
")",
"{",
"/**\n * Returns a map with 0 if the max ID row hasn't been initialized yet, \n * otherwise the map has actual data\n */",
"final",
"class",
"GetCB",
"implements",
"Callback",
"<",
"Map",
"<",
"String",
",",
"Long",
">",
",",
"ArrayList",
"<",
"KeyValue",
">",
">",
"{",
"@",
"Override",
"public",
"Map",
"<",
"String",
",",
"Long",
">",
"call",
"(",
"final",
"ArrayList",
"<",
"KeyValue",
">",
"row",
")",
"throws",
"Exception",
"{",
"final",
"Map",
"<",
"String",
",",
"Long",
">",
"results",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Long",
">",
"(",
"3",
")",
";",
"if",
"(",
"row",
"==",
"null",
"||",
"row",
".",
"isEmpty",
"(",
")",
")",
"{",
"// it could be the case that this is the first time the TSD has run",
"// and the user hasn't put any metrics in, so log and return 0s",
"LOG",
".",
"info",
"(",
"\"Could not find the UID assignment row\"",
")",
";",
"for",
"(",
"final",
"byte",
"[",
"]",
"kind",
":",
"kinds",
")",
"{",
"results",
".",
"put",
"(",
"new",
"String",
"(",
"kind",
",",
"CHARSET",
")",
",",
"0L",
")",
";",
"}",
"return",
"results",
";",
"}",
"for",
"(",
"final",
"KeyValue",
"column",
":",
"row",
")",
"{",
"results",
".",
"put",
"(",
"new",
"String",
"(",
"column",
".",
"qualifier",
"(",
")",
",",
"CHARSET",
")",
",",
"Bytes",
".",
"getLong",
"(",
"column",
".",
"value",
"(",
")",
")",
")",
";",
"}",
"// if the user is starting with a fresh UID table, we need to account",
"// for missing columns",
"for",
"(",
"final",
"byte",
"[",
"]",
"kind",
":",
"kinds",
")",
"{",
"if",
"(",
"results",
".",
"get",
"(",
"new",
"String",
"(",
"kind",
",",
"CHARSET",
")",
")",
"==",
"null",
")",
"{",
"results",
".",
"put",
"(",
"new",
"String",
"(",
"kind",
",",
"CHARSET",
")",
",",
"0L",
")",
";",
"}",
"}",
"return",
"results",
";",
"}",
"}",
"final",
"GetRequest",
"get",
"=",
"new",
"GetRequest",
"(",
"tsdb",
".",
"uidTable",
"(",
")",
",",
"MAXID_ROW",
")",
";",
"get",
".",
"family",
"(",
"ID_FAMILY",
")",
";",
"get",
".",
"qualifiers",
"(",
"kinds",
")",
";",
"return",
"tsdb",
".",
"getClient",
"(",
")",
".",
"get",
"(",
"get",
")",
".",
"addCallback",
"(",
"new",
"GetCB",
"(",
")",
")",
";",
"}"
] |
Returns a map of max UIDs from storage for the given list of UID types
@param tsdb The TSDB to which we belong
@param kinds A list of qualifiers to fetch
@return A map with the "kind" as the key and the maximum assigned UID as
the value
@since 2.0
|
[
"Returns",
"a",
"map",
"of",
"max",
"UIDs",
"from",
"storage",
"for",
"the",
"given",
"list",
"of",
"UID",
"types"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1700-L1746
|
13,702
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.preloadUidCache
|
public static void preloadUidCache(final TSDB tsdb,
final ByteMap<UniqueId> uid_cache_map) throws HBaseException {
int max_results = tsdb.getConfig().getInt(
"tsd.core.preload_uid_cache.max_entries");
LOG.info("Preloading uid cache with max_results=" + max_results);
if (max_results <= 0) {
return;
}
Scanner scanner = null;
try {
int num_rows = 0;
scanner = getSuggestScanner(tsdb.getClient(), tsdb.uidTable(), "", null,
max_results);
for (ArrayList<ArrayList<KeyValue>> rows = scanner.nextRows().join();
rows != null;
rows = scanner.nextRows().join()) {
for (final ArrayList<KeyValue> row : rows) {
for (KeyValue kv: row) {
final String name = fromBytes(kv.key());
final byte[] kind = kv.qualifier();
final byte[] id = kv.value();
LOG.debug("id='{}', name='{}', kind='{}'", Arrays.toString(id),
name, fromBytes(kind));
UniqueId uid_cache = uid_cache_map.get(kind);
if (uid_cache != null) {
uid_cache.cacheMapping(name, id);
}
}
num_rows += row.size();
row.clear(); // free()
if (num_rows >= max_results) {
break;
}
}
}
for (UniqueId unique_id_table : uid_cache_map.values()) {
LOG.info("After preloading, uid cache '{}' has {} ids and {} names.",
unique_id_table.kind(),
unique_id_table.use_lru ? unique_id_table.lru_id_cache.size() :
unique_id_table.id_cache.size(),
unique_id_table.use_lru ? unique_id_table.lru_name_cache.size() :
unique_id_table.name_cache.size());
}
} catch (Exception e) {
if (e instanceof HBaseException) {
throw (HBaseException)e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException("Error while preloading IDs", e);
}
} finally {
if (scanner != null) {
scanner.close();
}
}
}
|
java
|
public static void preloadUidCache(final TSDB tsdb,
final ByteMap<UniqueId> uid_cache_map) throws HBaseException {
int max_results = tsdb.getConfig().getInt(
"tsd.core.preload_uid_cache.max_entries");
LOG.info("Preloading uid cache with max_results=" + max_results);
if (max_results <= 0) {
return;
}
Scanner scanner = null;
try {
int num_rows = 0;
scanner = getSuggestScanner(tsdb.getClient(), tsdb.uidTable(), "", null,
max_results);
for (ArrayList<ArrayList<KeyValue>> rows = scanner.nextRows().join();
rows != null;
rows = scanner.nextRows().join()) {
for (final ArrayList<KeyValue> row : rows) {
for (KeyValue kv: row) {
final String name = fromBytes(kv.key());
final byte[] kind = kv.qualifier();
final byte[] id = kv.value();
LOG.debug("id='{}', name='{}', kind='{}'", Arrays.toString(id),
name, fromBytes(kind));
UniqueId uid_cache = uid_cache_map.get(kind);
if (uid_cache != null) {
uid_cache.cacheMapping(name, id);
}
}
num_rows += row.size();
row.clear(); // free()
if (num_rows >= max_results) {
break;
}
}
}
for (UniqueId unique_id_table : uid_cache_map.values()) {
LOG.info("After preloading, uid cache '{}' has {} ids and {} names.",
unique_id_table.kind(),
unique_id_table.use_lru ? unique_id_table.lru_id_cache.size() :
unique_id_table.id_cache.size(),
unique_id_table.use_lru ? unique_id_table.lru_name_cache.size() :
unique_id_table.name_cache.size());
}
} catch (Exception e) {
if (e instanceof HBaseException) {
throw (HBaseException)e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException("Error while preloading IDs", e);
}
} finally {
if (scanner != null) {
scanner.close();
}
}
}
|
[
"public",
"static",
"void",
"preloadUidCache",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"ByteMap",
"<",
"UniqueId",
">",
"uid_cache_map",
")",
"throws",
"HBaseException",
"{",
"int",
"max_results",
"=",
"tsdb",
".",
"getConfig",
"(",
")",
".",
"getInt",
"(",
"\"tsd.core.preload_uid_cache.max_entries\"",
")",
";",
"LOG",
".",
"info",
"(",
"\"Preloading uid cache with max_results=\"",
"+",
"max_results",
")",
";",
"if",
"(",
"max_results",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"Scanner",
"scanner",
"=",
"null",
";",
"try",
"{",
"int",
"num_rows",
"=",
"0",
";",
"scanner",
"=",
"getSuggestScanner",
"(",
"tsdb",
".",
"getClient",
"(",
")",
",",
"tsdb",
".",
"uidTable",
"(",
")",
",",
"\"\"",
",",
"null",
",",
"max_results",
")",
";",
"for",
"(",
"ArrayList",
"<",
"ArrayList",
"<",
"KeyValue",
">",
">",
"rows",
"=",
"scanner",
".",
"nextRows",
"(",
")",
".",
"join",
"(",
")",
";",
"rows",
"!=",
"null",
";",
"rows",
"=",
"scanner",
".",
"nextRows",
"(",
")",
".",
"join",
"(",
")",
")",
"{",
"for",
"(",
"final",
"ArrayList",
"<",
"KeyValue",
">",
"row",
":",
"rows",
")",
"{",
"for",
"(",
"KeyValue",
"kv",
":",
"row",
")",
"{",
"final",
"String",
"name",
"=",
"fromBytes",
"(",
"kv",
".",
"key",
"(",
")",
")",
";",
"final",
"byte",
"[",
"]",
"kind",
"=",
"kv",
".",
"qualifier",
"(",
")",
";",
"final",
"byte",
"[",
"]",
"id",
"=",
"kv",
".",
"value",
"(",
")",
";",
"LOG",
".",
"debug",
"(",
"\"id='{}', name='{}', kind='{}'\"",
",",
"Arrays",
".",
"toString",
"(",
"id",
")",
",",
"name",
",",
"fromBytes",
"(",
"kind",
")",
")",
";",
"UniqueId",
"uid_cache",
"=",
"uid_cache_map",
".",
"get",
"(",
"kind",
")",
";",
"if",
"(",
"uid_cache",
"!=",
"null",
")",
"{",
"uid_cache",
".",
"cacheMapping",
"(",
"name",
",",
"id",
")",
";",
"}",
"}",
"num_rows",
"+=",
"row",
".",
"size",
"(",
")",
";",
"row",
".",
"clear",
"(",
")",
";",
"// free()",
"if",
"(",
"num_rows",
">=",
"max_results",
")",
"{",
"break",
";",
"}",
"}",
"}",
"for",
"(",
"UniqueId",
"unique_id_table",
":",
"uid_cache_map",
".",
"values",
"(",
")",
")",
"{",
"LOG",
".",
"info",
"(",
"\"After preloading, uid cache '{}' has {} ids and {} names.\"",
",",
"unique_id_table",
".",
"kind",
"(",
")",
",",
"unique_id_table",
".",
"use_lru",
"?",
"unique_id_table",
".",
"lru_id_cache",
".",
"size",
"(",
")",
":",
"unique_id_table",
".",
"id_cache",
".",
"size",
"(",
")",
",",
"unique_id_table",
".",
"use_lru",
"?",
"unique_id_table",
".",
"lru_name_cache",
".",
"size",
"(",
")",
":",
"unique_id_table",
".",
"name_cache",
".",
"size",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"if",
"(",
"e",
"instanceof",
"HBaseException",
")",
"{",
"throw",
"(",
"HBaseException",
")",
"e",
";",
"}",
"else",
"if",
"(",
"e",
"instanceof",
"RuntimeException",
")",
"{",
"throw",
"(",
"RuntimeException",
")",
"e",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Error while preloading IDs\"",
",",
"e",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"scanner",
"!=",
"null",
")",
"{",
"scanner",
".",
"close",
"(",
")",
";",
"}",
"}",
"}"
] |
Pre-load UID caches, scanning up to "tsd.core.preload_uid_cache.max_entries"
rows from the UID table.
@param tsdb The TSDB to use
@param uid_cache_map A map of {@link UniqueId} objects keyed on the kind.
@throws HBaseException Passes any HBaseException from HBase scanner.
@throws RuntimeException Wraps any non HBaseException from HBase scanner.
@since 2.1
|
[
"Pre",
"-",
"load",
"UID",
"caches",
"scanning",
"up",
"to",
"tsd",
".",
"core",
".",
"preload_uid_cache",
".",
"max_entries",
"rows",
"from",
"the",
"UID",
"table",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1757-L1813
|
13,703
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.execute
|
@Override
public void execute(TSDB tsdb, HttpQuery query) throws IOException {
// the uri will be /api/vX/tree/? or /api/tree/?
final String[] uri = query.explodeAPIPath();
final String endpoint = uri.length > 1 ? uri[1] : "";
try {
if (endpoint.isEmpty()) {
handleTree(tsdb, query);
} else if (endpoint.toLowerCase().equals("branch")) {
handleBranch(tsdb, query);
} else if (endpoint.toLowerCase().equals("rule")) {
handleRule(tsdb, query);
} else if (endpoint.toLowerCase().equals("rules")) {
handleRules(tsdb, query);
} else if (endpoint.toLowerCase().equals("test")) {
handleTest(tsdb, query);
} else if (endpoint.toLowerCase().equals("collisions")) {
handleCollisionNotMatched(tsdb, query, true);
} else if (endpoint.toLowerCase().equals("notmatched")) {
handleCollisionNotMatched(tsdb, query, false);
} else {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"This endpoint is not supported");
}
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
@Override
public void execute(TSDB tsdb, HttpQuery query) throws IOException {
// the uri will be /api/vX/tree/? or /api/tree/?
final String[] uri = query.explodeAPIPath();
final String endpoint = uri.length > 1 ? uri[1] : "";
try {
if (endpoint.isEmpty()) {
handleTree(tsdb, query);
} else if (endpoint.toLowerCase().equals("branch")) {
handleBranch(tsdb, query);
} else if (endpoint.toLowerCase().equals("rule")) {
handleRule(tsdb, query);
} else if (endpoint.toLowerCase().equals("rules")) {
handleRules(tsdb, query);
} else if (endpoint.toLowerCase().equals("test")) {
handleTest(tsdb, query);
} else if (endpoint.toLowerCase().equals("collisions")) {
handleCollisionNotMatched(tsdb, query, true);
} else if (endpoint.toLowerCase().equals("notmatched")) {
handleCollisionNotMatched(tsdb, query, false);
} else {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"This endpoint is not supported");
}
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"@",
"Override",
"public",
"void",
"execute",
"(",
"TSDB",
"tsdb",
",",
"HttpQuery",
"query",
")",
"throws",
"IOException",
"{",
"// the uri will be /api/vX/tree/? or /api/tree/?",
"final",
"String",
"[",
"]",
"uri",
"=",
"query",
".",
"explodeAPIPath",
"(",
")",
";",
"final",
"String",
"endpoint",
"=",
"uri",
".",
"length",
">",
"1",
"?",
"uri",
"[",
"1",
"]",
":",
"\"\"",
";",
"try",
"{",
"if",
"(",
"endpoint",
".",
"isEmpty",
"(",
")",
")",
"{",
"handleTree",
"(",
"tsdb",
",",
"query",
")",
";",
"}",
"else",
"if",
"(",
"endpoint",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"branch\"",
")",
")",
"{",
"handleBranch",
"(",
"tsdb",
",",
"query",
")",
";",
"}",
"else",
"if",
"(",
"endpoint",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"rule\"",
")",
")",
"{",
"handleRule",
"(",
"tsdb",
",",
"query",
")",
";",
"}",
"else",
"if",
"(",
"endpoint",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"rules\"",
")",
")",
"{",
"handleRules",
"(",
"tsdb",
",",
"query",
")",
";",
"}",
"else",
"if",
"(",
"endpoint",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"test\"",
")",
")",
"{",
"handleTest",
"(",
"tsdb",
",",
"query",
")",
";",
"}",
"else",
"if",
"(",
"endpoint",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"collisions\"",
")",
")",
"{",
"handleCollisionNotMatched",
"(",
"tsdb",
",",
"query",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"endpoint",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"notmatched\"",
")",
")",
"{",
"handleCollisionNotMatched",
"(",
"tsdb",
",",
"query",
",",
"false",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"This endpoint is not supported\"",
")",
";",
"}",
"}",
"catch",
"(",
"BadRequestException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Routes the request to the proper handler
@param tsdb The TSDB to which we belong
@param query The HTTP query to use for parsing and responding
|
[
"Routes",
"the",
"request",
"to",
"the",
"proper",
"handler"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L53-L83
|
13,704
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.handleBranch
|
private void handleBranch(TSDB tsdb, HttpQuery query) {
if (query.getAPIMethod() != HttpMethod.GET) {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
try {
final int tree_id = parseTreeId(query, false);
final String branch_hex =
query.getQueryStringParam("branch");
// compile the branch ID. If the user did NOT supply a branch address,
// that would include the tree ID, then we fall back to the tree ID and
// the root for that tree
final byte[] branch_id;
if (branch_hex == null || branch_hex.isEmpty()) {
if (tree_id < 1) {
throw new BadRequestException(
"Missing or invalid branch and tree IDs");
}
branch_id = Tree.idToBytes(tree_id);
} else {
branch_id = Branch.stringToId(branch_hex);
}
// fetch it
final Branch branch = Branch.fetchBranch(tsdb, branch_id, true)
.joinUninterruptibly();
if (branch == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate branch '" + Branch.idToString(branch_id) +
"' for tree '" + Tree.bytesToId(branch_id) + "'");
}
query.sendReply(query.serializer().formatBranchV1(branch));
} catch (BadRequestException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
private void handleBranch(TSDB tsdb, HttpQuery query) {
if (query.getAPIMethod() != HttpMethod.GET) {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
try {
final int tree_id = parseTreeId(query, false);
final String branch_hex =
query.getQueryStringParam("branch");
// compile the branch ID. If the user did NOT supply a branch address,
// that would include the tree ID, then we fall back to the tree ID and
// the root for that tree
final byte[] branch_id;
if (branch_hex == null || branch_hex.isEmpty()) {
if (tree_id < 1) {
throw new BadRequestException(
"Missing or invalid branch and tree IDs");
}
branch_id = Tree.idToBytes(tree_id);
} else {
branch_id = Branch.stringToId(branch_hex);
}
// fetch it
final Branch branch = Branch.fetchBranch(tsdb, branch_id, true)
.joinUninterruptibly();
if (branch == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate branch '" + Branch.idToString(branch_id) +
"' for tree '" + Tree.bytesToId(branch_id) + "'");
}
query.sendReply(query.serializer().formatBranchV1(branch));
} catch (BadRequestException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"private",
"void",
"handleBranch",
"(",
"TSDB",
"tsdb",
",",
"HttpQuery",
"query",
")",
"{",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"!=",
"HttpMethod",
".",
"GET",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"BAD_REQUEST",
",",
"\"Unsupported HTTP request method\"",
")",
";",
"}",
"try",
"{",
"final",
"int",
"tree_id",
"=",
"parseTreeId",
"(",
"query",
",",
"false",
")",
";",
"final",
"String",
"branch_hex",
"=",
"query",
".",
"getQueryStringParam",
"(",
"\"branch\"",
")",
";",
"// compile the branch ID. If the user did NOT supply a branch address, ",
"// that would include the tree ID, then we fall back to the tree ID and",
"// the root for that tree",
"final",
"byte",
"[",
"]",
"branch_id",
";",
"if",
"(",
"branch_hex",
"==",
"null",
"||",
"branch_hex",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"tree_id",
"<",
"1",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Missing or invalid branch and tree IDs\"",
")",
";",
"}",
"branch_id",
"=",
"Tree",
".",
"idToBytes",
"(",
"tree_id",
")",
";",
"}",
"else",
"{",
"branch_id",
"=",
"Branch",
".",
"stringToId",
"(",
"branch_hex",
")",
";",
"}",
"// fetch it",
"final",
"Branch",
"branch",
"=",
"Branch",
".",
"fetchBranch",
"(",
"tsdb",
",",
"branch_id",
",",
"true",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"if",
"(",
"branch",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"Unable to locate branch '\"",
"+",
"Branch",
".",
"idToString",
"(",
"branch_id",
")",
"+",
"\"' for tree '\"",
"+",
"Tree",
".",
"bytesToId",
"(",
"branch_id",
")",
"+",
"\"'\"",
")",
";",
"}",
"query",
".",
"sendReply",
"(",
"query",
".",
"serializer",
"(",
")",
".",
"formatBranchV1",
"(",
"branch",
")",
")",
";",
"}",
"catch",
"(",
"BadRequestException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Attempts to retrieve a single branch and return it to the user. If the
requested branch doesn't exist, it returns a 404.
@param tsdb The TSDB to which we belong
@param query The HTTP query to work with
@throws BadRequestException if the request was invalid.
|
[
"Attempts",
"to",
"retrieve",
"a",
"single",
"branch",
"and",
"return",
"it",
"to",
"the",
"user",
".",
"If",
"the",
"requested",
"branch",
"doesn",
"t",
"exist",
"it",
"returns",
"a",
"404",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L210-L252
|
13,705
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.handleRule
|
private void handleRule(TSDB tsdb, HttpQuery query) {
final TreeRule rule;
if (query.hasContent()) {
rule = query.serializer().parseTreeRuleV1();
} else {
rule = parseRule(query);
}
try {
// no matter what, we'll need a tree to work with, so make sure it exists
Tree tree = null;
tree = Tree.fetchTree(tsdb, rule.getTreeId())
.joinUninterruptibly();
if (tree == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate tree: " + rule.getTreeId());
}
// if get, then we're just returning a rule from a tree
if (query.getAPIMethod() == HttpMethod.GET) {
final TreeRule tree_rule = tree.getRule(rule.getLevel(),
rule.getOrder());
if (tree_rule == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate rule: " + rule);
}
query.sendReply(query.serializer().formatTreeRuleV1(tree_rule));
} else if (query.getAPIMethod() == HttpMethod.POST || query.getAPIMethod() == HttpMethod.PUT) {
if (rule.syncToStorage(tsdb, (query.getAPIMethod() == HttpMethod.PUT))
.joinUninterruptibly()) {
final TreeRule stored_rule = TreeRule.fetchRule(tsdb,
rule.getTreeId(), rule.getLevel(), rule.getOrder())
.joinUninterruptibly();
query.sendReply(query.serializer().formatTreeRuleV1(stored_rule));
} else {
throw new RuntimeException("Unable to save rule " + rule +
" to storage");
}
} else if (query.getAPIMethod() == HttpMethod.DELETE) {
if (tree.getRule(rule.getLevel(), rule.getOrder()) == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate rule: " + rule);
}
TreeRule.deleteRule(tsdb, tree.getTreeId(), rule.getLevel(),
rule.getOrder()).joinUninterruptibly();
query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
} else {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
} catch (BadRequestException e) {
throw e;
} catch (IllegalStateException e) {
query.sendStatusOnly(HttpResponseStatus.NOT_MODIFIED);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
private void handleRule(TSDB tsdb, HttpQuery query) {
final TreeRule rule;
if (query.hasContent()) {
rule = query.serializer().parseTreeRuleV1();
} else {
rule = parseRule(query);
}
try {
// no matter what, we'll need a tree to work with, so make sure it exists
Tree tree = null;
tree = Tree.fetchTree(tsdb, rule.getTreeId())
.joinUninterruptibly();
if (tree == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate tree: " + rule.getTreeId());
}
// if get, then we're just returning a rule from a tree
if (query.getAPIMethod() == HttpMethod.GET) {
final TreeRule tree_rule = tree.getRule(rule.getLevel(),
rule.getOrder());
if (tree_rule == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate rule: " + rule);
}
query.sendReply(query.serializer().formatTreeRuleV1(tree_rule));
} else if (query.getAPIMethod() == HttpMethod.POST || query.getAPIMethod() == HttpMethod.PUT) {
if (rule.syncToStorage(tsdb, (query.getAPIMethod() == HttpMethod.PUT))
.joinUninterruptibly()) {
final TreeRule stored_rule = TreeRule.fetchRule(tsdb,
rule.getTreeId(), rule.getLevel(), rule.getOrder())
.joinUninterruptibly();
query.sendReply(query.serializer().formatTreeRuleV1(stored_rule));
} else {
throw new RuntimeException("Unable to save rule " + rule +
" to storage");
}
} else if (query.getAPIMethod() == HttpMethod.DELETE) {
if (tree.getRule(rule.getLevel(), rule.getOrder()) == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate rule: " + rule);
}
TreeRule.deleteRule(tsdb, tree.getTreeId(), rule.getLevel(),
rule.getOrder()).joinUninterruptibly();
query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
} else {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
} catch (BadRequestException e) {
throw e;
} catch (IllegalStateException e) {
query.sendStatusOnly(HttpResponseStatus.NOT_MODIFIED);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"private",
"void",
"handleRule",
"(",
"TSDB",
"tsdb",
",",
"HttpQuery",
"query",
")",
"{",
"final",
"TreeRule",
"rule",
";",
"if",
"(",
"query",
".",
"hasContent",
"(",
")",
")",
"{",
"rule",
"=",
"query",
".",
"serializer",
"(",
")",
".",
"parseTreeRuleV1",
"(",
")",
";",
"}",
"else",
"{",
"rule",
"=",
"parseRule",
"(",
"query",
")",
";",
"}",
"try",
"{",
"// no matter what, we'll need a tree to work with, so make sure it exists",
"Tree",
"tree",
"=",
"null",
";",
"tree",
"=",
"Tree",
".",
"fetchTree",
"(",
"tsdb",
",",
"rule",
".",
"getTreeId",
"(",
")",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"if",
"(",
"tree",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"Unable to locate tree: \"",
"+",
"rule",
".",
"getTreeId",
"(",
")",
")",
";",
"}",
"// if get, then we're just returning a rule from a tree",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"GET",
")",
"{",
"final",
"TreeRule",
"tree_rule",
"=",
"tree",
".",
"getRule",
"(",
"rule",
".",
"getLevel",
"(",
")",
",",
"rule",
".",
"getOrder",
"(",
")",
")",
";",
"if",
"(",
"tree_rule",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"Unable to locate rule: \"",
"+",
"rule",
")",
";",
"}",
"query",
".",
"sendReply",
"(",
"query",
".",
"serializer",
"(",
")",
".",
"formatTreeRuleV1",
"(",
"tree_rule",
")",
")",
";",
"}",
"else",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"POST",
"||",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"PUT",
")",
"{",
"if",
"(",
"rule",
".",
"syncToStorage",
"(",
"tsdb",
",",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"PUT",
")",
")",
".",
"joinUninterruptibly",
"(",
")",
")",
"{",
"final",
"TreeRule",
"stored_rule",
"=",
"TreeRule",
".",
"fetchRule",
"(",
"tsdb",
",",
"rule",
".",
"getTreeId",
"(",
")",
",",
"rule",
".",
"getLevel",
"(",
")",
",",
"rule",
".",
"getOrder",
"(",
")",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"query",
".",
"sendReply",
"(",
"query",
".",
"serializer",
"(",
")",
".",
"formatTreeRuleV1",
"(",
"stored_rule",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unable to save rule \"",
"+",
"rule",
"+",
"\" to storage\"",
")",
";",
"}",
"}",
"else",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"DELETE",
")",
"{",
"if",
"(",
"tree",
".",
"getRule",
"(",
"rule",
".",
"getLevel",
"(",
")",
",",
"rule",
".",
"getOrder",
"(",
")",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"Unable to locate rule: \"",
"+",
"rule",
")",
";",
"}",
"TreeRule",
".",
"deleteRule",
"(",
"tsdb",
",",
"tree",
".",
"getTreeId",
"(",
")",
",",
"rule",
".",
"getLevel",
"(",
")",
",",
"rule",
".",
"getOrder",
"(",
")",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"query",
".",
"sendStatusOnly",
"(",
"HttpResponseStatus",
".",
"NO_CONTENT",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"BAD_REQUEST",
",",
"\"Unsupported HTTP request method\"",
")",
";",
"}",
"}",
"catch",
"(",
"BadRequestException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"IllegalStateException",
"e",
")",
"{",
"query",
".",
"sendStatusOnly",
"(",
"HttpResponseStatus",
".",
"NOT_MODIFIED",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Handles the CRUD calls for a single rule, enabling adding, editing or
deleting the rule
@param tsdb The TSDB to which we belong
@param query The HTTP query to work with
@throws BadRequestException if the request was invalid.
|
[
"Handles",
"the",
"CRUD",
"calls",
"for",
"a",
"single",
"rule",
"enabling",
"adding",
"editing",
"or",
"deleting",
"the",
"rule"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L261-L329
|
13,706
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.handleRules
|
private void handleRules(TSDB tsdb, HttpQuery query) {
int tree_id = 0;
List<TreeRule> rules = null;
if (query.hasContent()) {
rules = query.serializer().parseTreeRulesV1();
if (rules == null || rules.isEmpty()) {
throw new BadRequestException("Missing tree rules");
}
// validate that they all belong to the same tree
tree_id = rules.get(0).getTreeId();
for (TreeRule rule : rules) {
if (rule.getTreeId() != tree_id) {
throw new BadRequestException(
"All rules must belong to the same tree");
}
}
} else {
tree_id = parseTreeId(query, false);
}
// make sure the tree exists
try {
if (Tree.fetchTree(tsdb, tree_id).joinUninterruptibly() == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate tree: " + tree_id);
}
if (query.getAPIMethod() == HttpMethod.POST || query.getAPIMethod() == HttpMethod.PUT) {
if (rules == null || rules.isEmpty()) {
if (rules == null || rules.isEmpty()) {
throw new BadRequestException("Missing tree rules");
}
}
// purge the existing tree rules if we're told to PUT
if (query.getAPIMethod() == HttpMethod.PUT) {
TreeRule.deleteAllRules(tsdb, tree_id).joinUninterruptibly();
}
for (TreeRule rule : rules) {
rule.syncToStorage(tsdb, query.getAPIMethod() == HttpMethod.PUT)
.joinUninterruptibly();
}
query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
} else if (query.getAPIMethod() == HttpMethod.DELETE) {
TreeRule.deleteAllRules(tsdb, tree_id).joinUninterruptibly();
query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
} else {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
} catch (BadRequestException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
private void handleRules(TSDB tsdb, HttpQuery query) {
int tree_id = 0;
List<TreeRule> rules = null;
if (query.hasContent()) {
rules = query.serializer().parseTreeRulesV1();
if (rules == null || rules.isEmpty()) {
throw new BadRequestException("Missing tree rules");
}
// validate that they all belong to the same tree
tree_id = rules.get(0).getTreeId();
for (TreeRule rule : rules) {
if (rule.getTreeId() != tree_id) {
throw new BadRequestException(
"All rules must belong to the same tree");
}
}
} else {
tree_id = parseTreeId(query, false);
}
// make sure the tree exists
try {
if (Tree.fetchTree(tsdb, tree_id).joinUninterruptibly() == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate tree: " + tree_id);
}
if (query.getAPIMethod() == HttpMethod.POST || query.getAPIMethod() == HttpMethod.PUT) {
if (rules == null || rules.isEmpty()) {
if (rules == null || rules.isEmpty()) {
throw new BadRequestException("Missing tree rules");
}
}
// purge the existing tree rules if we're told to PUT
if (query.getAPIMethod() == HttpMethod.PUT) {
TreeRule.deleteAllRules(tsdb, tree_id).joinUninterruptibly();
}
for (TreeRule rule : rules) {
rule.syncToStorage(tsdb, query.getAPIMethod() == HttpMethod.PUT)
.joinUninterruptibly();
}
query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
} else if (query.getAPIMethod() == HttpMethod.DELETE) {
TreeRule.deleteAllRules(tsdb, tree_id).joinUninterruptibly();
query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
} else {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
} catch (BadRequestException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"private",
"void",
"handleRules",
"(",
"TSDB",
"tsdb",
",",
"HttpQuery",
"query",
")",
"{",
"int",
"tree_id",
"=",
"0",
";",
"List",
"<",
"TreeRule",
">",
"rules",
"=",
"null",
";",
"if",
"(",
"query",
".",
"hasContent",
"(",
")",
")",
"{",
"rules",
"=",
"query",
".",
"serializer",
"(",
")",
".",
"parseTreeRulesV1",
"(",
")",
";",
"if",
"(",
"rules",
"==",
"null",
"||",
"rules",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Missing tree rules\"",
")",
";",
"}",
"// validate that they all belong to the same tree",
"tree_id",
"=",
"rules",
".",
"get",
"(",
"0",
")",
".",
"getTreeId",
"(",
")",
";",
"for",
"(",
"TreeRule",
"rule",
":",
"rules",
")",
"{",
"if",
"(",
"rule",
".",
"getTreeId",
"(",
")",
"!=",
"tree_id",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"All rules must belong to the same tree\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"tree_id",
"=",
"parseTreeId",
"(",
"query",
",",
"false",
")",
";",
"}",
"// make sure the tree exists",
"try",
"{",
"if",
"(",
"Tree",
".",
"fetchTree",
"(",
"tsdb",
",",
"tree_id",
")",
".",
"joinUninterruptibly",
"(",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"Unable to locate tree: \"",
"+",
"tree_id",
")",
";",
"}",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"POST",
"||",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"PUT",
")",
"{",
"if",
"(",
"rules",
"==",
"null",
"||",
"rules",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"rules",
"==",
"null",
"||",
"rules",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Missing tree rules\"",
")",
";",
"}",
"}",
"// purge the existing tree rules if we're told to PUT",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"PUT",
")",
"{",
"TreeRule",
".",
"deleteAllRules",
"(",
"tsdb",
",",
"tree_id",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"}",
"for",
"(",
"TreeRule",
"rule",
":",
"rules",
")",
"{",
"rule",
".",
"syncToStorage",
"(",
"tsdb",
",",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"PUT",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"}",
"query",
".",
"sendStatusOnly",
"(",
"HttpResponseStatus",
".",
"NO_CONTENT",
")",
";",
"}",
"else",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"DELETE",
")",
"{",
"TreeRule",
".",
"deleteAllRules",
"(",
"tsdb",
",",
"tree_id",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"query",
".",
"sendStatusOnly",
"(",
"HttpResponseStatus",
".",
"NO_CONTENT",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"BAD_REQUEST",
",",
"\"Unsupported HTTP request method\"",
")",
";",
"}",
"}",
"catch",
"(",
"BadRequestException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Handles requests to replace or delete all of the rules in the given tree.
It's an efficiency helper for cases where folks don't want to make a single
call per rule when updating many rules at once.
@param tsdb The TSDB to which we belong
@param query The HTTP query to work with
@throws BadRequestException if the request was invalid.
|
[
"Handles",
"requests",
"to",
"replace",
"or",
"delete",
"all",
"of",
"the",
"rules",
"in",
"the",
"given",
"tree",
".",
"It",
"s",
"an",
"efficiency",
"helper",
"for",
"cases",
"where",
"folks",
"don",
"t",
"want",
"to",
"make",
"a",
"single",
"call",
"per",
"rule",
"when",
"updating",
"many",
"rules",
"at",
"once",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L339-L401
|
13,707
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.handleCollisionNotMatched
|
private void handleCollisionNotMatched(TSDB tsdb, HttpQuery query, final boolean for_collisions) {
final Map<String, Object> map;
if (query.hasContent()) {
map = query.serializer().parseTreeTSUIDsListV1();
} else {
map = parseTSUIDsList(query);
}
final Integer tree_id = (Integer) map.get("treeId");
if (tree_id == null) {
throw new BadRequestException("Missing or invalid Tree ID");
}
// make sure the tree exists
try {
if (Tree.fetchTree(tsdb, tree_id).joinUninterruptibly() == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate tree: " + tree_id);
}
if (query.getAPIMethod() == HttpMethod.GET || query.getAPIMethod() == HttpMethod.POST ||
query.getAPIMethod() == HttpMethod.PUT) {
// ugly, but keeps from having to create a dedicated class just to
// convert one field.
@SuppressWarnings("unchecked")
final List<String> tsuids = (List<String>)map.get("tsuids");
final Map<String, String> results = for_collisions ?
Tree.fetchCollisions(tsdb, tree_id, tsuids).joinUninterruptibly() :
Tree.fetchNotMatched(tsdb, tree_id, tsuids).joinUninterruptibly();
query.sendReply(query.serializer().formatTreeCollisionNotMatchedV1(
results, for_collisions));
} else {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
} catch (ClassCastException e) {
throw new BadRequestException(
"Unable to convert the given data to a list", e);
} catch (BadRequestException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
private void handleCollisionNotMatched(TSDB tsdb, HttpQuery query, final boolean for_collisions) {
final Map<String, Object> map;
if (query.hasContent()) {
map = query.serializer().parseTreeTSUIDsListV1();
} else {
map = parseTSUIDsList(query);
}
final Integer tree_id = (Integer) map.get("treeId");
if (tree_id == null) {
throw new BadRequestException("Missing or invalid Tree ID");
}
// make sure the tree exists
try {
if (Tree.fetchTree(tsdb, tree_id).joinUninterruptibly() == null) {
throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
"Unable to locate tree: " + tree_id);
}
if (query.getAPIMethod() == HttpMethod.GET || query.getAPIMethod() == HttpMethod.POST ||
query.getAPIMethod() == HttpMethod.PUT) {
// ugly, but keeps from having to create a dedicated class just to
// convert one field.
@SuppressWarnings("unchecked")
final List<String> tsuids = (List<String>)map.get("tsuids");
final Map<String, String> results = for_collisions ?
Tree.fetchCollisions(tsdb, tree_id, tsuids).joinUninterruptibly() :
Tree.fetchNotMatched(tsdb, tree_id, tsuids).joinUninterruptibly();
query.sendReply(query.serializer().formatTreeCollisionNotMatchedV1(
results, for_collisions));
} else {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
"Unsupported HTTP request method");
}
} catch (ClassCastException e) {
throw new BadRequestException(
"Unable to convert the given data to a list", e);
} catch (BadRequestException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"private",
"void",
"handleCollisionNotMatched",
"(",
"TSDB",
"tsdb",
",",
"HttpQuery",
"query",
",",
"final",
"boolean",
"for_collisions",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"Object",
">",
"map",
";",
"if",
"(",
"query",
".",
"hasContent",
"(",
")",
")",
"{",
"map",
"=",
"query",
".",
"serializer",
"(",
")",
".",
"parseTreeTSUIDsListV1",
"(",
")",
";",
"}",
"else",
"{",
"map",
"=",
"parseTSUIDsList",
"(",
"query",
")",
";",
"}",
"final",
"Integer",
"tree_id",
"=",
"(",
"Integer",
")",
"map",
".",
"get",
"(",
"\"treeId\"",
")",
";",
"if",
"(",
"tree_id",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Missing or invalid Tree ID\"",
")",
";",
"}",
"// make sure the tree exists",
"try",
"{",
"if",
"(",
"Tree",
".",
"fetchTree",
"(",
"tsdb",
",",
"tree_id",
")",
".",
"joinUninterruptibly",
"(",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"NOT_FOUND",
",",
"\"Unable to locate tree: \"",
"+",
"tree_id",
")",
";",
"}",
"if",
"(",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"GET",
"||",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"POST",
"||",
"query",
".",
"getAPIMethod",
"(",
")",
"==",
"HttpMethod",
".",
"PUT",
")",
"{",
"// ugly, but keeps from having to create a dedicated class just to ",
"// convert one field.",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"final",
"List",
"<",
"String",
">",
"tsuids",
"=",
"(",
"List",
"<",
"String",
">",
")",
"map",
".",
"get",
"(",
"\"tsuids\"",
")",
";",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"results",
"=",
"for_collisions",
"?",
"Tree",
".",
"fetchCollisions",
"(",
"tsdb",
",",
"tree_id",
",",
"tsuids",
")",
".",
"joinUninterruptibly",
"(",
")",
":",
"Tree",
".",
"fetchNotMatched",
"(",
"tsdb",
",",
"tree_id",
",",
"tsuids",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"query",
".",
"sendReply",
"(",
"query",
".",
"serializer",
"(",
")",
".",
"formatTreeCollisionNotMatchedV1",
"(",
"results",
",",
"for_collisions",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"BAD_REQUEST",
",",
"\"Unsupported HTTP request method\"",
")",
";",
"}",
"}",
"catch",
"(",
"ClassCastException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to convert the given data to a list\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"BadRequestException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Handles requests to fetch collisions or not-matched entries for the given
tree. To cut down on code, this method uses a flag to determine if we want
collisions or not-matched entries, since they both have the same data types.
@param tsdb The TSDB to which we belong
@param query The HTTP query to work with
@param for_collisions
|
[
"Handles",
"requests",
"to",
"fetch",
"collisions",
"or",
"not",
"-",
"matched",
"entries",
"for",
"the",
"given",
"tree",
".",
"To",
"cut",
"down",
"on",
"code",
"this",
"method",
"uses",
"a",
"flag",
"to",
"determine",
"if",
"we",
"want",
"collisions",
"or",
"not",
"-",
"matched",
"entries",
"since",
"they",
"both",
"have",
"the",
"same",
"data",
"types",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L516-L565
|
13,708
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.parseTree
|
private Tree parseTree(HttpQuery query) {
final Tree tree = new Tree(parseTreeId(query, false));
if (query.hasQueryStringParam("name")) {
tree.setName(query.getQueryStringParam("name"));
}
if (query.hasQueryStringParam("description")) {
tree.setDescription(query.getQueryStringParam("description"));
}
if (query.hasQueryStringParam("notes")) {
tree.setNotes(query.getQueryStringParam("notes"));
}
if (query.hasQueryStringParam("strict_match")) {
if (query.getQueryStringParam("strict_match").toLowerCase()
.equals("true")) {
tree.setStrictMatch(true);
} else {
tree.setStrictMatch(false);
}
}
if (query.hasQueryStringParam("enabled")) {
final String enabled = query.getQueryStringParam("enabled");
if (enabled.toLowerCase().equals("true")) {
tree.setEnabled(true);
} else {
tree.setEnabled(false);
}
}
if (query.hasQueryStringParam("store_failures")) {
if (query.getQueryStringParam("store_failures").toLowerCase()
.equals("true")) {
tree.setStoreFailures(true);
} else {
tree.setStoreFailures(false);
}
}
return tree;
}
|
java
|
private Tree parseTree(HttpQuery query) {
final Tree tree = new Tree(parseTreeId(query, false));
if (query.hasQueryStringParam("name")) {
tree.setName(query.getQueryStringParam("name"));
}
if (query.hasQueryStringParam("description")) {
tree.setDescription(query.getQueryStringParam("description"));
}
if (query.hasQueryStringParam("notes")) {
tree.setNotes(query.getQueryStringParam("notes"));
}
if (query.hasQueryStringParam("strict_match")) {
if (query.getQueryStringParam("strict_match").toLowerCase()
.equals("true")) {
tree.setStrictMatch(true);
} else {
tree.setStrictMatch(false);
}
}
if (query.hasQueryStringParam("enabled")) {
final String enabled = query.getQueryStringParam("enabled");
if (enabled.toLowerCase().equals("true")) {
tree.setEnabled(true);
} else {
tree.setEnabled(false);
}
}
if (query.hasQueryStringParam("store_failures")) {
if (query.getQueryStringParam("store_failures").toLowerCase()
.equals("true")) {
tree.setStoreFailures(true);
} else {
tree.setStoreFailures(false);
}
}
return tree;
}
|
[
"private",
"Tree",
"parseTree",
"(",
"HttpQuery",
"query",
")",
"{",
"final",
"Tree",
"tree",
"=",
"new",
"Tree",
"(",
"parseTreeId",
"(",
"query",
",",
"false",
")",
")",
";",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"name\"",
")",
")",
"{",
"tree",
".",
"setName",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"name\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"description\"",
")",
")",
"{",
"tree",
".",
"setDescription",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"description\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"notes\"",
")",
")",
"{",
"tree",
".",
"setNotes",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"notes\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"strict_match\"",
")",
")",
"{",
"if",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"strict_match\"",
")",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"true\"",
")",
")",
"{",
"tree",
".",
"setStrictMatch",
"(",
"true",
")",
";",
"}",
"else",
"{",
"tree",
".",
"setStrictMatch",
"(",
"false",
")",
";",
"}",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"enabled\"",
")",
")",
"{",
"final",
"String",
"enabled",
"=",
"query",
".",
"getQueryStringParam",
"(",
"\"enabled\"",
")",
";",
"if",
"(",
"enabled",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"true\"",
")",
")",
"{",
"tree",
".",
"setEnabled",
"(",
"true",
")",
";",
"}",
"else",
"{",
"tree",
".",
"setEnabled",
"(",
"false",
")",
";",
"}",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"store_failures\"",
")",
")",
"{",
"if",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"store_failures\"",
")",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"true\"",
")",
")",
"{",
"tree",
".",
"setStoreFailures",
"(",
"true",
")",
";",
"}",
"else",
"{",
"tree",
".",
"setStoreFailures",
"(",
"false",
")",
";",
"}",
"}",
"return",
"tree",
";",
"}"
] |
Parses query string parameters into a blank tree object. Used for updating
tree meta data.
@param query The HTTP query to work with
@return A tree object filled in with changes
@throws BadRequestException if some of the data was invalid
|
[
"Parses",
"query",
"string",
"parameters",
"into",
"a",
"blank",
"tree",
"object",
".",
"Used",
"for",
"updating",
"tree",
"meta",
"data",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L574-L610
|
13,709
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.parseRule
|
private TreeRule parseRule(HttpQuery query) {
final TreeRule rule = new TreeRule(parseTreeId(query, true));
if (query.hasQueryStringParam("type")) {
try {
rule.setType(TreeRule.stringToType(query.getQueryStringParam("type")));
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unable to parse the 'type' parameter", e);
}
}
if (query.hasQueryStringParam("field")) {
rule.setField(query.getQueryStringParam("field"));
}
if (query.hasQueryStringParam("custom_field")) {
rule.setCustomField(query.getQueryStringParam("custom_field"));
}
if (query.hasQueryStringParam("regex")) {
try {
rule.setRegex(query.getQueryStringParam("regex"));
} catch (PatternSyntaxException e) {
throw new BadRequestException(
"Unable to parse the 'regex' parameter", e);
}
}
if (query.hasQueryStringParam("separator")) {
rule.setSeparator(query.getQueryStringParam("separator"));
}
if (query.hasQueryStringParam("description")) {
rule.setDescription(query.getQueryStringParam("description"));
}
if (query.hasQueryStringParam("notes")) {
rule.setNotes(query.getQueryStringParam("notes"));
}
if (query.hasQueryStringParam("regex_group_idx")) {
try {
rule.setRegexGroupIdx(Integer.parseInt(
query.getQueryStringParam("regex_group_idx")));
} catch (NumberFormatException e) {
throw new BadRequestException(
"Unable to parse the 'regex_group_idx' parameter", e);
}
}
if (query.hasQueryStringParam("display_format")) {
rule.setDisplayFormat(query.getQueryStringParam("display_format"));
}
//if (query.hasQueryStringParam("level")) {
try {
rule.setLevel(Integer.parseInt(
query.getRequiredQueryStringParam("level")));
} catch (NumberFormatException e) {
throw new BadRequestException(
"Unable to parse the 'level' parameter", e);
}
//}
//if (query.hasQueryStringParam("order")) {
try {
rule.setOrder(Integer.parseInt(
query.getRequiredQueryStringParam("order")));
} catch (NumberFormatException e) {
throw new BadRequestException(
"Unable to parse the 'order' parameter", e);
}
//}
return rule;
}
|
java
|
private TreeRule parseRule(HttpQuery query) {
final TreeRule rule = new TreeRule(parseTreeId(query, true));
if (query.hasQueryStringParam("type")) {
try {
rule.setType(TreeRule.stringToType(query.getQueryStringParam("type")));
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unable to parse the 'type' parameter", e);
}
}
if (query.hasQueryStringParam("field")) {
rule.setField(query.getQueryStringParam("field"));
}
if (query.hasQueryStringParam("custom_field")) {
rule.setCustomField(query.getQueryStringParam("custom_field"));
}
if (query.hasQueryStringParam("regex")) {
try {
rule.setRegex(query.getQueryStringParam("regex"));
} catch (PatternSyntaxException e) {
throw new BadRequestException(
"Unable to parse the 'regex' parameter", e);
}
}
if (query.hasQueryStringParam("separator")) {
rule.setSeparator(query.getQueryStringParam("separator"));
}
if (query.hasQueryStringParam("description")) {
rule.setDescription(query.getQueryStringParam("description"));
}
if (query.hasQueryStringParam("notes")) {
rule.setNotes(query.getQueryStringParam("notes"));
}
if (query.hasQueryStringParam("regex_group_idx")) {
try {
rule.setRegexGroupIdx(Integer.parseInt(
query.getQueryStringParam("regex_group_idx")));
} catch (NumberFormatException e) {
throw new BadRequestException(
"Unable to parse the 'regex_group_idx' parameter", e);
}
}
if (query.hasQueryStringParam("display_format")) {
rule.setDisplayFormat(query.getQueryStringParam("display_format"));
}
//if (query.hasQueryStringParam("level")) {
try {
rule.setLevel(Integer.parseInt(
query.getRequiredQueryStringParam("level")));
} catch (NumberFormatException e) {
throw new BadRequestException(
"Unable to parse the 'level' parameter", e);
}
//}
//if (query.hasQueryStringParam("order")) {
try {
rule.setOrder(Integer.parseInt(
query.getRequiredQueryStringParam("order")));
} catch (NumberFormatException e) {
throw new BadRequestException(
"Unable to parse the 'order' parameter", e);
}
//}
return rule;
}
|
[
"private",
"TreeRule",
"parseRule",
"(",
"HttpQuery",
"query",
")",
"{",
"final",
"TreeRule",
"rule",
"=",
"new",
"TreeRule",
"(",
"parseTreeId",
"(",
"query",
",",
"true",
")",
")",
";",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"type\"",
")",
")",
"{",
"try",
"{",
"rule",
".",
"setType",
"(",
"TreeRule",
".",
"stringToType",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"type\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse the 'type' parameter\"",
",",
"e",
")",
";",
"}",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"field\"",
")",
")",
"{",
"rule",
".",
"setField",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"field\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"custom_field\"",
")",
")",
"{",
"rule",
".",
"setCustomField",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"custom_field\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"regex\"",
")",
")",
"{",
"try",
"{",
"rule",
".",
"setRegex",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"regex\"",
")",
")",
";",
"}",
"catch",
"(",
"PatternSyntaxException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse the 'regex' parameter\"",
",",
"e",
")",
";",
"}",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"separator\"",
")",
")",
"{",
"rule",
".",
"setSeparator",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"separator\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"description\"",
")",
")",
"{",
"rule",
".",
"setDescription",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"description\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"notes\"",
")",
")",
"{",
"rule",
".",
"setNotes",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"notes\"",
")",
")",
";",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"regex_group_idx\"",
")",
")",
"{",
"try",
"{",
"rule",
".",
"setRegexGroupIdx",
"(",
"Integer",
".",
"parseInt",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"regex_group_idx\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse the 'regex_group_idx' parameter\"",
",",
"e",
")",
";",
"}",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"display_format\"",
")",
")",
"{",
"rule",
".",
"setDisplayFormat",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"display_format\"",
")",
")",
";",
"}",
"//if (query.hasQueryStringParam(\"level\")) {",
"try",
"{",
"rule",
".",
"setLevel",
"(",
"Integer",
".",
"parseInt",
"(",
"query",
".",
"getRequiredQueryStringParam",
"(",
"\"level\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse the 'level' parameter\"",
",",
"e",
")",
";",
"}",
"//}",
"//if (query.hasQueryStringParam(\"order\")) {",
"try",
"{",
"rule",
".",
"setOrder",
"(",
"Integer",
".",
"parseInt",
"(",
"query",
".",
"getRequiredQueryStringParam",
"(",
"\"order\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse the 'order' parameter\"",
",",
"e",
")",
";",
"}",
"//}",
"return",
"rule",
";",
"}"
] |
Parses query string parameters into a blank tree rule object. Used for
updating individual rules
@param query The HTTP query to work with
@return A rule object filled in with changes
@throws BadRequestException if some of the data was invalid
|
[
"Parses",
"query",
"string",
"parameters",
"into",
"a",
"blank",
"tree",
"rule",
"object",
".",
"Used",
"for",
"updating",
"individual",
"rules"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L619-L683
|
13,710
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.parseTreeId
|
private int parseTreeId(HttpQuery query, final boolean required) {
try{
if (required) {
return Integer.parseInt(query.getRequiredQueryStringParam("treeid"));
} else {
if (query.hasQueryStringParam("treeid")) {
return Integer.parseInt(query.getQueryStringParam("treeid"));
} else {
return 0;
}
}
} catch (NumberFormatException nfe) {
throw new BadRequestException("Unable to parse 'tree' value", nfe);
}
}
|
java
|
private int parseTreeId(HttpQuery query, final boolean required) {
try{
if (required) {
return Integer.parseInt(query.getRequiredQueryStringParam("treeid"));
} else {
if (query.hasQueryStringParam("treeid")) {
return Integer.parseInt(query.getQueryStringParam("treeid"));
} else {
return 0;
}
}
} catch (NumberFormatException nfe) {
throw new BadRequestException("Unable to parse 'tree' value", nfe);
}
}
|
[
"private",
"int",
"parseTreeId",
"(",
"HttpQuery",
"query",
",",
"final",
"boolean",
"required",
")",
"{",
"try",
"{",
"if",
"(",
"required",
")",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"query",
".",
"getRequiredQueryStringParam",
"(",
"\"treeid\"",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"treeid\"",
")",
")",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"query",
".",
"getQueryStringParam",
"(",
"\"treeid\"",
")",
")",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}",
"}",
"catch",
"(",
"NumberFormatException",
"nfe",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse 'tree' value\"",
",",
"nfe",
")",
";",
"}",
"}"
] |
Parses the tree ID from a query
Used often so it's been broken into it's own method
@param query The HTTP query to work with
@param required Whether or not the ID is required for the given call
@return The tree ID or 0 if not provided
|
[
"Parses",
"the",
"tree",
"ID",
"from",
"a",
"query",
"Used",
"often",
"so",
"it",
"s",
"been",
"broken",
"into",
"it",
"s",
"own",
"method"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L692-L706
|
13,711
|
OpenTSDB/opentsdb
|
src/tsd/TreeRpc.java
|
TreeRpc.parseTSUIDsList
|
private Map<String, Object> parseTSUIDsList(HttpQuery query) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("treeId", parseTreeId(query, true));
final String tsquery = query.getQueryStringParam("tsuids");
if (tsquery != null) {
final String[] tsuids = tsquery.split(",");
map.put("tsuids", Arrays.asList(tsuids));
}
return map;
}
|
java
|
private Map<String, Object> parseTSUIDsList(HttpQuery query) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("treeId", parseTreeId(query, true));
final String tsquery = query.getQueryStringParam("tsuids");
if (tsquery != null) {
final String[] tsuids = tsquery.split(",");
map.put("tsuids", Arrays.asList(tsuids));
}
return map;
}
|
[
"private",
"Map",
"<",
"String",
",",
"Object",
">",
"parseTSUIDsList",
"(",
"HttpQuery",
"query",
")",
"{",
"final",
"HashMap",
"<",
"String",
",",
"Object",
">",
"map",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Object",
">",
"(",
")",
";",
"map",
".",
"put",
"(",
"\"treeId\"",
",",
"parseTreeId",
"(",
"query",
",",
"true",
")",
")",
";",
"final",
"String",
"tsquery",
"=",
"query",
".",
"getQueryStringParam",
"(",
"\"tsuids\"",
")",
";",
"if",
"(",
"tsquery",
"!=",
"null",
")",
"{",
"final",
"String",
"[",
"]",
"tsuids",
"=",
"tsquery",
".",
"split",
"(",
"\",\"",
")",
";",
"map",
".",
"put",
"(",
"\"tsuids\"",
",",
"Arrays",
".",
"asList",
"(",
"tsuids",
")",
")",
";",
"}",
"return",
"map",
";",
"}"
] |
Used to parse a list of TSUIDs from the query string for collision or not
matched requests. TSUIDs must be comma separated.
@param query The HTTP query to work with
@return A map with a list of tsuids. If found, the tsuids array will be
under the "tsuid" key. The map is necessary for compatability with POJO
parsing.
|
[
"Used",
"to",
"parse",
"a",
"list",
"of",
"TSUIDs",
"from",
"the",
"query",
"string",
"for",
"collision",
"or",
"not",
"matched",
"requests",
".",
"TSUIDs",
"must",
"be",
"comma",
"separated",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/TreeRpc.java#L716-L727
|
13,712
|
OpenTSDB/opentsdb
|
src/graph/Plot.java
|
Plot.setParams
|
public void setParams(final Map<String, String> params) {
// check "format y" and "format y2"
String[] y_format_keys = {"format y", "format y2"};
for(String k : y_format_keys){
if(params.containsKey(k)){
params.put(k, URLDecoder.decode(params.get(k)));
}
}
this.params = params;
}
|
java
|
public void setParams(final Map<String, String> params) {
// check "format y" and "format y2"
String[] y_format_keys = {"format y", "format y2"};
for(String k : y_format_keys){
if(params.containsKey(k)){
params.put(k, URLDecoder.decode(params.get(k)));
}
}
this.params = params;
}
|
[
"public",
"void",
"setParams",
"(",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"params",
")",
"{",
"// check \"format y\" and \"format y2\"",
"String",
"[",
"]",
"y_format_keys",
"=",
"{",
"\"format y\"",
",",
"\"format y2\"",
"}",
";",
"for",
"(",
"String",
"k",
":",
"y_format_keys",
")",
"{",
"if",
"(",
"params",
".",
"containsKey",
"(",
"k",
")",
")",
"{",
"params",
".",
"put",
"(",
"k",
",",
"URLDecoder",
".",
"decode",
"(",
"params",
".",
"get",
"(",
"k",
")",
")",
")",
";",
"}",
"}",
"this",
".",
"params",
"=",
"params",
";",
"}"
] |
Sets the global parameters for this plot.
@param params Each entry is a Gnuplot setting that will be written as-is
in the Gnuplot script file: {@code set KEY VALUE}.
When the value is {@code null} the script will instead contain
{@code unset KEY}.
<p>
Special parameters with a special meaning (since OpenTSDB 1.1):
<ul>
<li>{@code bgcolor}: Either {@code transparent} or an RGB color in
hexadecimal (with a leading 'x' as in {@code x01AB23}).</li>
<li>{@code fgcolor}: An RGB color in hexadecimal ({@code x42BEE7}).</li>
</ul>
|
[
"Sets",
"the",
"global",
"parameters",
"for",
"this",
"plot",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/graph/Plot.java#L137-L146
|
13,713
|
OpenTSDB/opentsdb
|
src/graph/Plot.java
|
Plot.add
|
public void add(final DataPoints datapoints,
final String options) {
// Technically, we could check the number of data points in the
// datapoints argument in order to do something when there are none, but
// this is potentially expensive with a SpanGroup since it requires
// iterating through the entire SpanGroup. We'll check this later
// when we're trying to use the data, in order to avoid multiple passes
// through the entire data.
this.datapoints.add(datapoints);
this.options.add(options);
}
|
java
|
public void add(final DataPoints datapoints,
final String options) {
// Technically, we could check the number of data points in the
// datapoints argument in order to do something when there are none, but
// this is potentially expensive with a SpanGroup since it requires
// iterating through the entire SpanGroup. We'll check this later
// when we're trying to use the data, in order to avoid multiple passes
// through the entire data.
this.datapoints.add(datapoints);
this.options.add(options);
}
|
[
"public",
"void",
"add",
"(",
"final",
"DataPoints",
"datapoints",
",",
"final",
"String",
"options",
")",
"{",
"// Technically, we could check the number of data points in the",
"// datapoints argument in order to do something when there are none, but",
"// this is potentially expensive with a SpanGroup since it requires",
"// iterating through the entire SpanGroup. We'll check this later",
"// when we're trying to use the data, in order to avoid multiple passes",
"// through the entire data.",
"this",
".",
"datapoints",
".",
"add",
"(",
"datapoints",
")",
";",
"this",
".",
"options",
".",
"add",
"(",
"options",
")",
";",
"}"
] |
Adds some data points to this plot.
@param datapoints The data points to plot.
@param options The options to apply to this specific series.
|
[
"Adds",
"some",
"data",
"points",
"to",
"this",
"plot",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/graph/Plot.java#L175-L185
|
13,714
|
OpenTSDB/opentsdb
|
src/graph/Plot.java
|
Plot.dumpToFiles
|
public int dumpToFiles(final String basepath) throws IOException {
int npoints = 0;
final int nseries = datapoints.size();
final String datafiles[] = nseries > 0 ? new String[nseries] : null;
FileSystem.checkDirectory(new File(basepath).getParent(),
Const.MUST_BE_WRITEABLE, Const.CREATE_IF_NEEDED);
for (int i = 0; i < nseries; i++) {
datafiles[i] = basepath + "_" + i + ".dat";
final PrintWriter datafile = new PrintWriter(datafiles[i]);
try {
for (final DataPoint d : datapoints.get(i)) {
final long ts = d.timestamp() / 1000;
if (d.isInteger()) {
datafile.print(ts + utc_offset);
datafile.print(' ');
datafile.print(d.longValue());
} else {
final double value = d.doubleValue();
if (Double.isInfinite(value)) {
// Infinity is invalid.
throw new IllegalStateException("Infinity found in"
+ " datapoints #" + i + ": " + value + " d=" + d);
} else if (Double.isNaN(value)) {
// NaNs should be skipped.
continue;
}
datafile.print(ts + utc_offset);
datafile.print(' ');
datafile.print(value);
}
datafile.print('\n');
if (ts >= (start_time & UNSIGNED) && ts <= (end_time & UNSIGNED)) {
npoints++;
}
}
} finally {
datafile.close();
}
}
if (npoints == 0) {
// Gnuplot doesn't like empty graphs when xrange and yrange aren't
// entirely defined, because it can't decide on good ranges with no
// data. We always set the xrange, but the yrange is supplied by the
// user. Let's make sure it defines a min and a max.
params.put("yrange", "[0:10]"); // Doesn't matter what values we use.
}
writeGnuplotScript(basepath, datafiles);
return npoints;
}
|
java
|
public int dumpToFiles(final String basepath) throws IOException {
int npoints = 0;
final int nseries = datapoints.size();
final String datafiles[] = nseries > 0 ? new String[nseries] : null;
FileSystem.checkDirectory(new File(basepath).getParent(),
Const.MUST_BE_WRITEABLE, Const.CREATE_IF_NEEDED);
for (int i = 0; i < nseries; i++) {
datafiles[i] = basepath + "_" + i + ".dat";
final PrintWriter datafile = new PrintWriter(datafiles[i]);
try {
for (final DataPoint d : datapoints.get(i)) {
final long ts = d.timestamp() / 1000;
if (d.isInteger()) {
datafile.print(ts + utc_offset);
datafile.print(' ');
datafile.print(d.longValue());
} else {
final double value = d.doubleValue();
if (Double.isInfinite(value)) {
// Infinity is invalid.
throw new IllegalStateException("Infinity found in"
+ " datapoints #" + i + ": " + value + " d=" + d);
} else if (Double.isNaN(value)) {
// NaNs should be skipped.
continue;
}
datafile.print(ts + utc_offset);
datafile.print(' ');
datafile.print(value);
}
datafile.print('\n');
if (ts >= (start_time & UNSIGNED) && ts <= (end_time & UNSIGNED)) {
npoints++;
}
}
} finally {
datafile.close();
}
}
if (npoints == 0) {
// Gnuplot doesn't like empty graphs when xrange and yrange aren't
// entirely defined, because it can't decide on good ranges with no
// data. We always set the xrange, but the yrange is supplied by the
// user. Let's make sure it defines a min and a max.
params.put("yrange", "[0:10]"); // Doesn't matter what values we use.
}
writeGnuplotScript(basepath, datafiles);
return npoints;
}
|
[
"public",
"int",
"dumpToFiles",
"(",
"final",
"String",
"basepath",
")",
"throws",
"IOException",
"{",
"int",
"npoints",
"=",
"0",
";",
"final",
"int",
"nseries",
"=",
"datapoints",
".",
"size",
"(",
")",
";",
"final",
"String",
"datafiles",
"[",
"]",
"=",
"nseries",
">",
"0",
"?",
"new",
"String",
"[",
"nseries",
"]",
":",
"null",
";",
"FileSystem",
".",
"checkDirectory",
"(",
"new",
"File",
"(",
"basepath",
")",
".",
"getParent",
"(",
")",
",",
"Const",
".",
"MUST_BE_WRITEABLE",
",",
"Const",
".",
"CREATE_IF_NEEDED",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nseries",
";",
"i",
"++",
")",
"{",
"datafiles",
"[",
"i",
"]",
"=",
"basepath",
"+",
"\"_\"",
"+",
"i",
"+",
"\".dat\"",
";",
"final",
"PrintWriter",
"datafile",
"=",
"new",
"PrintWriter",
"(",
"datafiles",
"[",
"i",
"]",
")",
";",
"try",
"{",
"for",
"(",
"final",
"DataPoint",
"d",
":",
"datapoints",
".",
"get",
"(",
"i",
")",
")",
"{",
"final",
"long",
"ts",
"=",
"d",
".",
"timestamp",
"(",
")",
"/",
"1000",
";",
"if",
"(",
"d",
".",
"isInteger",
"(",
")",
")",
"{",
"datafile",
".",
"print",
"(",
"ts",
"+",
"utc_offset",
")",
";",
"datafile",
".",
"print",
"(",
"'",
"'",
")",
";",
"datafile",
".",
"print",
"(",
"d",
".",
"longValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"final",
"double",
"value",
"=",
"d",
".",
"doubleValue",
"(",
")",
";",
"if",
"(",
"Double",
".",
"isInfinite",
"(",
"value",
")",
")",
"{",
"// Infinity is invalid.",
"throw",
"new",
"IllegalStateException",
"(",
"\"Infinity found in\"",
"+",
"\" datapoints #\"",
"+",
"i",
"+",
"\": \"",
"+",
"value",
"+",
"\" d=\"",
"+",
"d",
")",
";",
"}",
"else",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"value",
")",
")",
"{",
"// NaNs should be skipped.",
"continue",
";",
"}",
"datafile",
".",
"print",
"(",
"ts",
"+",
"utc_offset",
")",
";",
"datafile",
".",
"print",
"(",
"'",
"'",
")",
";",
"datafile",
".",
"print",
"(",
"value",
")",
";",
"}",
"datafile",
".",
"print",
"(",
"'",
"'",
")",
";",
"if",
"(",
"ts",
">=",
"(",
"start_time",
"&",
"UNSIGNED",
")",
"&&",
"ts",
"<=",
"(",
"end_time",
"&",
"UNSIGNED",
")",
")",
"{",
"npoints",
"++",
";",
"}",
"}",
"}",
"finally",
"{",
"datafile",
".",
"close",
"(",
")",
";",
"}",
"}",
"if",
"(",
"npoints",
"==",
"0",
")",
"{",
"// Gnuplot doesn't like empty graphs when xrange and yrange aren't",
"// entirely defined, because it can't decide on good ranges with no",
"// data. We always set the xrange, but the yrange is supplied by the",
"// user. Let's make sure it defines a min and a max.",
"params",
".",
"put",
"(",
"\"yrange\"",
",",
"\"[0:10]\"",
")",
";",
"// Doesn't matter what values we use.",
"}",
"writeGnuplotScript",
"(",
"basepath",
",",
"datafiles",
")",
";",
"return",
"npoints",
";",
"}"
] |
Generates the Gnuplot script and data files.
@param basepath The base path to use. A number of new files will be
created and their names will all start with this string.
@return The number of data points sent to Gnuplot. This can be less
than the number of data points involved in the query due to things like
aggregation or downsampling.
@throws IOException if there was an error while writing one of the files.
|
[
"Generates",
"the",
"Gnuplot",
"script",
"and",
"data",
"files",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/graph/Plot.java#L204-L257
|
13,715
|
OpenTSDB/opentsdb
|
src/utils/Exceptions.java
|
Exceptions.getCause
|
public static Throwable getCause(final DeferredGroupException e) {
Throwable ex = e;
while (ex.getClass().equals(DeferredGroupException.class)) {
if (ex.getCause() == null) {
break;
} else {
ex = ex.getCause();
}
}
return ex;
}
|
java
|
public static Throwable getCause(final DeferredGroupException e) {
Throwable ex = e;
while (ex.getClass().equals(DeferredGroupException.class)) {
if (ex.getCause() == null) {
break;
} else {
ex = ex.getCause();
}
}
return ex;
}
|
[
"public",
"static",
"Throwable",
"getCause",
"(",
"final",
"DeferredGroupException",
"e",
")",
"{",
"Throwable",
"ex",
"=",
"e",
";",
"while",
"(",
"ex",
".",
"getClass",
"(",
")",
".",
"equals",
"(",
"DeferredGroupException",
".",
"class",
")",
")",
"{",
"if",
"(",
"ex",
".",
"getCause",
"(",
")",
"==",
"null",
")",
"{",
"break",
";",
"}",
"else",
"{",
"ex",
"=",
"ex",
".",
"getCause",
"(",
")",
";",
"}",
"}",
"return",
"ex",
";",
"}"
] |
Iterates through the stack trace, looking for the actual cause of the
deferred group exception. These traces can be huge and truncated in the
logs so it's really useful to be able to spit out the source.
@param e A DeferredGroupException to parse
@return The root cause of the exception if found.
|
[
"Iterates",
"through",
"the",
"stack",
"trace",
"looking",
"for",
"the",
"actual",
"cause",
"of",
"the",
"deferred",
"group",
"exception",
".",
"These",
"traces",
"can",
"be",
"huge",
"and",
"truncated",
"in",
"the",
"logs",
"so",
"it",
"s",
"really",
"useful",
"to",
"be",
"able",
"to",
"spit",
"out",
"the",
"source",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/Exceptions.java#L30-L40
|
13,716
|
OpenTSDB/opentsdb
|
src/core/ByteBufferList.java
|
ByteBufferList.add
|
public void add(final byte[] buf, final int offset, final int len) {
segments.add(new BufferSegment(buf, offset, len));
total_length += len;
}
|
java
|
public void add(final byte[] buf, final int offset, final int len) {
segments.add(new BufferSegment(buf, offset, len));
total_length += len;
}
|
[
"public",
"void",
"add",
"(",
"final",
"byte",
"[",
"]",
"buf",
",",
"final",
"int",
"offset",
",",
"final",
"int",
"len",
")",
"{",
"segments",
".",
"add",
"(",
"new",
"BufferSegment",
"(",
"buf",
",",
"offset",
",",
"len",
")",
")",
";",
"total_length",
"+=",
"len",
";",
"}"
] |
Add a segment to the buffer list.
@param buf byte array
@param offset offset into buf
@param len length of segment, starting at offset
|
[
"Add",
"a",
"segment",
"to",
"the",
"buffer",
"list",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/ByteBufferList.java#L56-L59
|
13,717
|
OpenTSDB/opentsdb
|
src/core/ByteBufferList.java
|
ByteBufferList.getLastSegment
|
public byte[] getLastSegment() {
if (segments.isEmpty()) {
return null;
}
BufferSegment seg = segments.get(segments.size() - 1);
return Arrays.copyOfRange(seg.buf, seg.offset, seg.offset + seg.len);
}
|
java
|
public byte[] getLastSegment() {
if (segments.isEmpty()) {
return null;
}
BufferSegment seg = segments.get(segments.size() - 1);
return Arrays.copyOfRange(seg.buf, seg.offset, seg.offset + seg.len);
}
|
[
"public",
"byte",
"[",
"]",
"getLastSegment",
"(",
")",
"{",
"if",
"(",
"segments",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"BufferSegment",
"seg",
"=",
"segments",
".",
"get",
"(",
"segments",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"return",
"Arrays",
".",
"copyOfRange",
"(",
"seg",
".",
"buf",
",",
"seg",
".",
"offset",
",",
"seg",
".",
"offset",
"+",
"seg",
".",
"len",
")",
";",
"}"
] |
Get the most recently added segment.
@return byte array, a copy of the most recently added segment
|
[
"Get",
"the",
"most",
"recently",
"added",
"segment",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/ByteBufferList.java#L66-L72
|
13,718
|
OpenTSDB/opentsdb
|
src/utils/ByteArrayPair.java
|
ByteArrayPair.compareTo
|
public int compareTo(ByteArrayPair a) {
final int key_compare = Bytes.memcmpMaybeNull(this.key, a.key);
if (key_compare == 0) {
return Bytes.memcmpMaybeNull(this.value, a.value);
}
return key_compare;
}
|
java
|
public int compareTo(ByteArrayPair a) {
final int key_compare = Bytes.memcmpMaybeNull(this.key, a.key);
if (key_compare == 0) {
return Bytes.memcmpMaybeNull(this.value, a.value);
}
return key_compare;
}
|
[
"public",
"int",
"compareTo",
"(",
"ByteArrayPair",
"a",
")",
"{",
"final",
"int",
"key_compare",
"=",
"Bytes",
".",
"memcmpMaybeNull",
"(",
"this",
".",
"key",
",",
"a",
".",
"key",
")",
";",
"if",
"(",
"key_compare",
"==",
"0",
")",
"{",
"return",
"Bytes",
".",
"memcmpMaybeNull",
"(",
"this",
".",
"value",
",",
"a",
".",
"value",
")",
";",
"}",
"return",
"key_compare",
";",
"}"
] |
Sorts on the key first then on the value. Nulls are allowed and are ordered
first.
@param a The value to compare against.
|
[
"Sorts",
"on",
"the",
"key",
"first",
"then",
"on",
"the",
"value",
".",
"Nulls",
"are",
"allowed",
"and",
"are",
"ordered",
"first",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/utils/ByteArrayPair.java#L45-L51
|
13,719
|
OpenTSDB/opentsdb
|
src/core/AggregationIterator.java
|
AggregationIterator.hasNextValue
|
private boolean hasNextValue(boolean update_pos) {
final int size = iterators.length;
for (int i = pos + 1; i < size; i++) {
if (timestamps[i] != 0) {
//LOG.debug("hasNextValue -> true #" + i);
if (update_pos) {
pos = i;
}
return true;
}
}
//LOG.debug("hasNextValue -> false (ran out)");
return false;
}
|
java
|
private boolean hasNextValue(boolean update_pos) {
final int size = iterators.length;
for (int i = pos + 1; i < size; i++) {
if (timestamps[i] != 0) {
//LOG.debug("hasNextValue -> true #" + i);
if (update_pos) {
pos = i;
}
return true;
}
}
//LOG.debug("hasNextValue -> false (ran out)");
return false;
}
|
[
"private",
"boolean",
"hasNextValue",
"(",
"boolean",
"update_pos",
")",
"{",
"final",
"int",
"size",
"=",
"iterators",
".",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"pos",
"+",
"1",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"if",
"(",
"timestamps",
"[",
"i",
"]",
"!=",
"0",
")",
"{",
"//LOG.debug(\"hasNextValue -> true #\" + i);",
"if",
"(",
"update_pos",
")",
"{",
"pos",
"=",
"i",
";",
"}",
"return",
"true",
";",
"}",
"}",
"//LOG.debug(\"hasNextValue -> false (ran out)\");",
"return",
"false",
";",
"}"
] |
Returns whether or not there are more values to aggregate.
@param update_pos Whether or not to also move the internal pointer
{@link #pos} to the index of the next value to aggregate.
@return true if there are more values to aggregate, false otherwise.
|
[
"Returns",
"whether",
"or",
"not",
"there",
"are",
"more",
"values",
"to",
"aggregate",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/AggregationIterator.java#L667-L680
|
13,720
|
OpenTSDB/opentsdb
|
src/core/Span.java
|
Span.addRow
|
protected void addRow(final KeyValue row) {
long last_ts = 0;
if (rows.size() != 0) {
// Verify that we have the same metric id and tags.
final byte[] key = row.key();
final iRowSeq last = rows.get(rows.size() - 1);
final short metric_width = tsdb.metrics.width();
final short tags_offset =
(short) (Const.SALT_WIDTH() + metric_width + Const.TIMESTAMP_BYTES);
final short tags_bytes = (short) (key.length - tags_offset);
String error = null;
if (key.length != last.key().length) {
error = "row key length mismatch";
} else if (
Bytes.memcmp(key, last.key(), Const.SALT_WIDTH(), metric_width) != 0) {
error = "metric ID mismatch";
} else if (Bytes.memcmp(key, last.key(), tags_offset, tags_bytes) != 0) {
error = "tags mismatch";
}
if (error != null) {
throw new IllegalArgumentException(error + ". "
+ "This Span's last row key is " + Arrays.toString(last.key())
+ " whereas the row key being added is " + Arrays.toString(key)
+ " and metric_width=" + metric_width);
}
last_ts = last.timestamp(last.size() - 1); // O(n)
}
final RowSeq rowseq = new RowSeq(tsdb);
rowseq.setRow(row);
sorted = false;
if (last_ts >= rowseq.timestamp(0)) {
// scan to see if we need to merge into an existing row
for (final iRowSeq rs : rows) {
if (Bytes.memcmp(rs.key(), row.key(), Const.SALT_WIDTH(),
(rs.key().length - Const.SALT_WIDTH())) == 0) {
rs.addRow(row);
return;
}
}
}
rows.add(rowseq);
}
|
java
|
protected void addRow(final KeyValue row) {
long last_ts = 0;
if (rows.size() != 0) {
// Verify that we have the same metric id and tags.
final byte[] key = row.key();
final iRowSeq last = rows.get(rows.size() - 1);
final short metric_width = tsdb.metrics.width();
final short tags_offset =
(short) (Const.SALT_WIDTH() + metric_width + Const.TIMESTAMP_BYTES);
final short tags_bytes = (short) (key.length - tags_offset);
String error = null;
if (key.length != last.key().length) {
error = "row key length mismatch";
} else if (
Bytes.memcmp(key, last.key(), Const.SALT_WIDTH(), metric_width) != 0) {
error = "metric ID mismatch";
} else if (Bytes.memcmp(key, last.key(), tags_offset, tags_bytes) != 0) {
error = "tags mismatch";
}
if (error != null) {
throw new IllegalArgumentException(error + ". "
+ "This Span's last row key is " + Arrays.toString(last.key())
+ " whereas the row key being added is " + Arrays.toString(key)
+ " and metric_width=" + metric_width);
}
last_ts = last.timestamp(last.size() - 1); // O(n)
}
final RowSeq rowseq = new RowSeq(tsdb);
rowseq.setRow(row);
sorted = false;
if (last_ts >= rowseq.timestamp(0)) {
// scan to see if we need to merge into an existing row
for (final iRowSeq rs : rows) {
if (Bytes.memcmp(rs.key(), row.key(), Const.SALT_WIDTH(),
(rs.key().length - Const.SALT_WIDTH())) == 0) {
rs.addRow(row);
return;
}
}
}
rows.add(rowseq);
}
|
[
"protected",
"void",
"addRow",
"(",
"final",
"KeyValue",
"row",
")",
"{",
"long",
"last_ts",
"=",
"0",
";",
"if",
"(",
"rows",
".",
"size",
"(",
")",
"!=",
"0",
")",
"{",
"// Verify that we have the same metric id and tags.",
"final",
"byte",
"[",
"]",
"key",
"=",
"row",
".",
"key",
"(",
")",
";",
"final",
"iRowSeq",
"last",
"=",
"rows",
".",
"get",
"(",
"rows",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"final",
"short",
"metric_width",
"=",
"tsdb",
".",
"metrics",
".",
"width",
"(",
")",
";",
"final",
"short",
"tags_offset",
"=",
"(",
"short",
")",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"metric_width",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
")",
";",
"final",
"short",
"tags_bytes",
"=",
"(",
"short",
")",
"(",
"key",
".",
"length",
"-",
"tags_offset",
")",
";",
"String",
"error",
"=",
"null",
";",
"if",
"(",
"key",
".",
"length",
"!=",
"last",
".",
"key",
"(",
")",
".",
"length",
")",
"{",
"error",
"=",
"\"row key length mismatch\"",
";",
"}",
"else",
"if",
"(",
"Bytes",
".",
"memcmp",
"(",
"key",
",",
"last",
".",
"key",
"(",
")",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
",",
"metric_width",
")",
"!=",
"0",
")",
"{",
"error",
"=",
"\"metric ID mismatch\"",
";",
"}",
"else",
"if",
"(",
"Bytes",
".",
"memcmp",
"(",
"key",
",",
"last",
".",
"key",
"(",
")",
",",
"tags_offset",
",",
"tags_bytes",
")",
"!=",
"0",
")",
"{",
"error",
"=",
"\"tags mismatch\"",
";",
"}",
"if",
"(",
"error",
"!=",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"error",
"+",
"\". \"",
"+",
"\"This Span's last row key is \"",
"+",
"Arrays",
".",
"toString",
"(",
"last",
".",
"key",
"(",
")",
")",
"+",
"\" whereas the row key being added is \"",
"+",
"Arrays",
".",
"toString",
"(",
"key",
")",
"+",
"\" and metric_width=\"",
"+",
"metric_width",
")",
";",
"}",
"last_ts",
"=",
"last",
".",
"timestamp",
"(",
"last",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"// O(n)",
"}",
"final",
"RowSeq",
"rowseq",
"=",
"new",
"RowSeq",
"(",
"tsdb",
")",
";",
"rowseq",
".",
"setRow",
"(",
"row",
")",
";",
"sorted",
"=",
"false",
";",
"if",
"(",
"last_ts",
">=",
"rowseq",
".",
"timestamp",
"(",
"0",
")",
")",
"{",
"// scan to see if we need to merge into an existing row",
"for",
"(",
"final",
"iRowSeq",
"rs",
":",
"rows",
")",
"{",
"if",
"(",
"Bytes",
".",
"memcmp",
"(",
"rs",
".",
"key",
"(",
")",
",",
"row",
".",
"key",
"(",
")",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
",",
"(",
"rs",
".",
"key",
"(",
")",
".",
"length",
"-",
"Const",
".",
"SALT_WIDTH",
"(",
")",
")",
")",
"==",
"0",
")",
"{",
"rs",
".",
"addRow",
"(",
"row",
")",
";",
"return",
";",
"}",
"}",
"}",
"rows",
".",
"add",
"(",
"rowseq",
")",
";",
"}"
] |
Adds a compacted row to the span, merging with an existing RowSeq or
creating a new one if necessary.
@param row The compacted row to add to this span.
@throws IllegalArgumentException if the argument and this span are for
two different time series.
|
[
"Adds",
"a",
"compacted",
"row",
"to",
"the",
"span",
"merging",
"with",
"an",
"existing",
"RowSeq",
"or",
"creating",
"a",
"new",
"one",
"if",
"necessary",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Span.java#L177-L220
|
13,721
|
OpenTSDB/opentsdb
|
src/core/Span.java
|
Span.seekRow
|
private int seekRow(final long timestamp) {
checkRowOrder();
int row_index = 0;
iRowSeq row = null;
final int nrows = rows.size();
for (int i = 0; i < nrows; i++) {
row = rows.get(i);
final int sz = row.size();
if (sz < 1) {
row_index++;
} else if (row.timestamp(sz - 1) < timestamp) {
row_index++; // The last DP in this row is before 'timestamp'.
} else {
break;
}
}
if (row_index == nrows) { // If this timestamp was too large for the
--row_index; // last row, return the last row.
}
return row_index;
}
|
java
|
private int seekRow(final long timestamp) {
checkRowOrder();
int row_index = 0;
iRowSeq row = null;
final int nrows = rows.size();
for (int i = 0; i < nrows; i++) {
row = rows.get(i);
final int sz = row.size();
if (sz < 1) {
row_index++;
} else if (row.timestamp(sz - 1) < timestamp) {
row_index++; // The last DP in this row is before 'timestamp'.
} else {
break;
}
}
if (row_index == nrows) { // If this timestamp was too large for the
--row_index; // last row, return the last row.
}
return row_index;
}
|
[
"private",
"int",
"seekRow",
"(",
"final",
"long",
"timestamp",
")",
"{",
"checkRowOrder",
"(",
")",
";",
"int",
"row_index",
"=",
"0",
";",
"iRowSeq",
"row",
"=",
"null",
";",
"final",
"int",
"nrows",
"=",
"rows",
".",
"size",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nrows",
";",
"i",
"++",
")",
"{",
"row",
"=",
"rows",
".",
"get",
"(",
"i",
")",
";",
"final",
"int",
"sz",
"=",
"row",
".",
"size",
"(",
")",
";",
"if",
"(",
"sz",
"<",
"1",
")",
"{",
"row_index",
"++",
";",
"}",
"else",
"if",
"(",
"row",
".",
"timestamp",
"(",
"sz",
"-",
"1",
")",
"<",
"timestamp",
")",
"{",
"row_index",
"++",
";",
"// The last DP in this row is before 'timestamp'.",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"row_index",
"==",
"nrows",
")",
"{",
"// If this timestamp was too large for the",
"--",
"row_index",
";",
"// last row, return the last row.",
"}",
"return",
"row_index",
";",
"}"
] |
Finds the index of the row in which the given timestamp should be.
@param timestamp A strictly positive 32-bit integer.
@return A strictly positive index in the {@code rows} array.
|
[
"Finds",
"the",
"index",
"of",
"the",
"row",
"in",
"which",
"the",
"given",
"timestamp",
"should",
"be",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Span.java#L360-L380
|
13,722
|
OpenTSDB/opentsdb
|
src/core/Span.java
|
Span.spanIterator
|
Span.Iterator spanIterator() {
if (!sorted) {
Collections.sort(rows, new RowSeq.RowSeqComparator());
sorted = true;
}
return new Span.Iterator();
}
|
java
|
Span.Iterator spanIterator() {
if (!sorted) {
Collections.sort(rows, new RowSeq.RowSeqComparator());
sorted = true;
}
return new Span.Iterator();
}
|
[
"Span",
".",
"Iterator",
"spanIterator",
"(",
")",
"{",
"if",
"(",
"!",
"sorted",
")",
"{",
"Collections",
".",
"sort",
"(",
"rows",
",",
"new",
"RowSeq",
".",
"RowSeqComparator",
"(",
")",
")",
";",
"sorted",
"=",
"true",
";",
"}",
"return",
"new",
"Span",
".",
"Iterator",
"(",
")",
";",
"}"
] |
Package private iterator method to access it as a Span.Iterator.
|
[
"Package",
"private",
"iterator",
"method",
"to",
"access",
"it",
"as",
"a",
"Span",
".",
"Iterator",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Span.java#L395-L401
|
13,723
|
OpenTSDB/opentsdb
|
src/core/Span.java
|
Span.downsampler
|
Downsampler downsampler(final long start_time,
final long end_time,
final long interval_ms,
final Aggregator downsampler,
final FillPolicy fill_policy) {
if (FillPolicy.NONE == fill_policy) {
// The default downsampler simply skips missing intervals, causing the
// span group to linearly interpolate.
return new Downsampler(spanIterator(), interval_ms, downsampler);
} else {
// Otherwise, we need to instantiate a downsampler that can fill missing
// intervals with special values.
return new FillingDownsampler(spanIterator(), start_time, end_time,
interval_ms, downsampler, fill_policy);
}
}
|
java
|
Downsampler downsampler(final long start_time,
final long end_time,
final long interval_ms,
final Aggregator downsampler,
final FillPolicy fill_policy) {
if (FillPolicy.NONE == fill_policy) {
// The default downsampler simply skips missing intervals, causing the
// span group to linearly interpolate.
return new Downsampler(spanIterator(), interval_ms, downsampler);
} else {
// Otherwise, we need to instantiate a downsampler that can fill missing
// intervals with special values.
return new FillingDownsampler(spanIterator(), start_time, end_time,
interval_ms, downsampler, fill_policy);
}
}
|
[
"Downsampler",
"downsampler",
"(",
"final",
"long",
"start_time",
",",
"final",
"long",
"end_time",
",",
"final",
"long",
"interval_ms",
",",
"final",
"Aggregator",
"downsampler",
",",
"final",
"FillPolicy",
"fill_policy",
")",
"{",
"if",
"(",
"FillPolicy",
".",
"NONE",
"==",
"fill_policy",
")",
"{",
"// The default downsampler simply skips missing intervals, causing the",
"// span group to linearly interpolate.",
"return",
"new",
"Downsampler",
"(",
"spanIterator",
"(",
")",
",",
"interval_ms",
",",
"downsampler",
")",
";",
"}",
"else",
"{",
"// Otherwise, we need to instantiate a downsampler that can fill missing",
"// intervals with special values.",
"return",
"new",
"FillingDownsampler",
"(",
"spanIterator",
"(",
")",
",",
"start_time",
",",
"end_time",
",",
"interval_ms",
",",
"downsampler",
",",
"fill_policy",
")",
";",
"}",
"}"
] |
Package private iterator method to access data while downsampling with the
option to force interpolation.
@param start_time The time in milliseconds at which the data begins.
@param end_time The time in milliseconds at which the data ends.
@param interval_ms The interval in milli seconds wanted between each data
point.
@param downsampler The downsampling function to use.
@param fill_policy Policy specifying whether to interpolate or to fill
missing intervals with special values.
@return A new downsampler.
|
[
"Package",
"private",
"iterator",
"method",
"to",
"access",
"data",
"while",
"downsampling",
"with",
"the",
"option",
"to",
"force",
"interpolation",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Span.java#L493-L508
|
13,724
|
OpenTSDB/opentsdb
|
src/tools/MetaPurge.java
|
MetaPurge.run
|
public void run() {
long purged_columns;
try {
purged_columns = purgeUIDMeta().joinUninterruptibly();
LOG.info("Thread [" + thread_id + "] finished. Purged [" +
purged_columns + "] UIDMeta columns from storage");
purged_columns = purgeTSMeta().joinUninterruptibly();
LOG.info("Thread [" + thread_id + "] finished. Purged [" +
purged_columns + "] TSMeta columns from storage");
} catch (Exception e) {
LOG.error("Unexpected exception", e);
}
}
|
java
|
public void run() {
long purged_columns;
try {
purged_columns = purgeUIDMeta().joinUninterruptibly();
LOG.info("Thread [" + thread_id + "] finished. Purged [" +
purged_columns + "] UIDMeta columns from storage");
purged_columns = purgeTSMeta().joinUninterruptibly();
LOG.info("Thread [" + thread_id + "] finished. Purged [" +
purged_columns + "] TSMeta columns from storage");
} catch (Exception e) {
LOG.error("Unexpected exception", e);
}
}
|
[
"public",
"void",
"run",
"(",
")",
"{",
"long",
"purged_columns",
";",
"try",
"{",
"purged_columns",
"=",
"purgeUIDMeta",
"(",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"LOG",
".",
"info",
"(",
"\"Thread [\"",
"+",
"thread_id",
"+",
"\"] finished. Purged [\"",
"+",
"purged_columns",
"+",
"\"] UIDMeta columns from storage\"",
")",
";",
"purged_columns",
"=",
"purgeTSMeta",
"(",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"LOG",
".",
"info",
"(",
"\"Thread [\"",
"+",
"thread_id",
"+",
"\"] finished. Purged [\"",
"+",
"purged_columns",
"+",
"\"] TSMeta columns from storage\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Unexpected exception\"",
",",
"e",
")",
";",
"}",
"}"
] |
Loops through the entire tsdb-uid table, then the meta data table and exits
when complete.
|
[
"Loops",
"through",
"the",
"entire",
"tsdb",
"-",
"uid",
"table",
"then",
"the",
"meta",
"data",
"table",
"and",
"exits",
"when",
"complete",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/MetaPurge.java#L81-L95
|
13,725
|
OpenTSDB/opentsdb
|
src/tools/MetaPurge.java
|
MetaPurge.purgeUIDMeta
|
public Deferred<Long> purgeUIDMeta() {
// a list to store all pending deletes so we don't exit before they've
// completed
final ArrayList<Deferred<Object>> delete_calls =
new ArrayList<Deferred<Object>>();
final Deferred<Long> result = new Deferred<Long>();
/**
* Scanner callback that will recursively call itself and loop through the
* rows of the UID table, issuing delete requests for all of the columns in
* a row that match a meta qualifier.
*/
final class MetaScanner implements Callback<Deferred<Long>,
ArrayList<ArrayList<KeyValue>>> {
final Scanner scanner;
public MetaScanner() {
scanner = getScanner(tsdb.uidTable());
}
/**
* Fetches the next group of rows from the scanner and sets this class as
* a callback
* @return The total number of columns deleted after completion
*/
public Deferred<Long> scan() {
return scanner.nextRows().addCallbackDeferring(this);
}
@Override
public Deferred<Long> call(ArrayList<ArrayList<KeyValue>> rows)
throws Exception {
if (rows == null) {
result.callback(columns);
return null;
}
for (final ArrayList<KeyValue> row : rows) {
// one delete request per row. We'll almost always delete the whole
// row, so preallocate some ram.
ArrayList<byte[]> qualifiers = new ArrayList<byte[]>(row.size());
for (KeyValue column : row) {
if (Bytes.equals(TSMeta.META_QUALIFIER(), column.qualifier())) {
qualifiers.add(column.qualifier());
} else if (Bytes.equals("metric_meta".getBytes(CHARSET),
column.qualifier())) {
qualifiers.add(column.qualifier());
} else if (Bytes.equals("tagk_meta".getBytes(CHARSET),
column.qualifier())) {
qualifiers.add(column.qualifier());
} else if (Bytes.equals("tagv_meta".getBytes(CHARSET),
column.qualifier())) {
qualifiers.add(column.qualifier());
}
}
if (qualifiers.size() > 0) {
columns += qualifiers.size();
final DeleteRequest delete = new DeleteRequest(tsdb.uidTable(),
row.get(0).key(), NAME_FAMILY,
qualifiers.toArray(new byte[qualifiers.size()][]));
delete_calls.add(tsdb.getClient().delete(delete));
}
}
/**
* Buffer callback used to wait on all of the delete calls for the
* last set of rows returned from the scanner so we don't fill up the
* deferreds array and OOM out.
*/
final class ContinueCB implements Callback<Deferred<Long>,
ArrayList<Object>> {
@Override
public Deferred<Long> call(ArrayList<Object> deletes)
throws Exception {
LOG.debug("[" + thread_id + "] Processed [" + deletes.size()
+ "] delete calls");
delete_calls.clear();
return scan();
}
}
// fetch the next set of rows after waiting for current set of delete
// requests to complete
Deferred.group(delete_calls).addCallbackDeferring(new ContinueCB());
return null;
}
}
// start the scan
new MetaScanner().scan();
return result;
}
|
java
|
public Deferred<Long> purgeUIDMeta() {
// a list to store all pending deletes so we don't exit before they've
// completed
final ArrayList<Deferred<Object>> delete_calls =
new ArrayList<Deferred<Object>>();
final Deferred<Long> result = new Deferred<Long>();
/**
* Scanner callback that will recursively call itself and loop through the
* rows of the UID table, issuing delete requests for all of the columns in
* a row that match a meta qualifier.
*/
final class MetaScanner implements Callback<Deferred<Long>,
ArrayList<ArrayList<KeyValue>>> {
final Scanner scanner;
public MetaScanner() {
scanner = getScanner(tsdb.uidTable());
}
/**
* Fetches the next group of rows from the scanner and sets this class as
* a callback
* @return The total number of columns deleted after completion
*/
public Deferred<Long> scan() {
return scanner.nextRows().addCallbackDeferring(this);
}
@Override
public Deferred<Long> call(ArrayList<ArrayList<KeyValue>> rows)
throws Exception {
if (rows == null) {
result.callback(columns);
return null;
}
for (final ArrayList<KeyValue> row : rows) {
// one delete request per row. We'll almost always delete the whole
// row, so preallocate some ram.
ArrayList<byte[]> qualifiers = new ArrayList<byte[]>(row.size());
for (KeyValue column : row) {
if (Bytes.equals(TSMeta.META_QUALIFIER(), column.qualifier())) {
qualifiers.add(column.qualifier());
} else if (Bytes.equals("metric_meta".getBytes(CHARSET),
column.qualifier())) {
qualifiers.add(column.qualifier());
} else if (Bytes.equals("tagk_meta".getBytes(CHARSET),
column.qualifier())) {
qualifiers.add(column.qualifier());
} else if (Bytes.equals("tagv_meta".getBytes(CHARSET),
column.qualifier())) {
qualifiers.add(column.qualifier());
}
}
if (qualifiers.size() > 0) {
columns += qualifiers.size();
final DeleteRequest delete = new DeleteRequest(tsdb.uidTable(),
row.get(0).key(), NAME_FAMILY,
qualifiers.toArray(new byte[qualifiers.size()][]));
delete_calls.add(tsdb.getClient().delete(delete));
}
}
/**
* Buffer callback used to wait on all of the delete calls for the
* last set of rows returned from the scanner so we don't fill up the
* deferreds array and OOM out.
*/
final class ContinueCB implements Callback<Deferred<Long>,
ArrayList<Object>> {
@Override
public Deferred<Long> call(ArrayList<Object> deletes)
throws Exception {
LOG.debug("[" + thread_id + "] Processed [" + deletes.size()
+ "] delete calls");
delete_calls.clear();
return scan();
}
}
// fetch the next set of rows after waiting for current set of delete
// requests to complete
Deferred.group(delete_calls).addCallbackDeferring(new ContinueCB());
return null;
}
}
// start the scan
new MetaScanner().scan();
return result;
}
|
[
"public",
"Deferred",
"<",
"Long",
">",
"purgeUIDMeta",
"(",
")",
"{",
"// a list to store all pending deletes so we don't exit before they've ",
"// completed",
"final",
"ArrayList",
"<",
"Deferred",
"<",
"Object",
">",
">",
"delete_calls",
"=",
"new",
"ArrayList",
"<",
"Deferred",
"<",
"Object",
">",
">",
"(",
")",
";",
"final",
"Deferred",
"<",
"Long",
">",
"result",
"=",
"new",
"Deferred",
"<",
"Long",
">",
"(",
")",
";",
"/**\n * Scanner callback that will recursively call itself and loop through the\n * rows of the UID table, issuing delete requests for all of the columns in\n * a row that match a meta qualifier.\n */",
"final",
"class",
"MetaScanner",
"implements",
"Callback",
"<",
"Deferred",
"<",
"Long",
">",
",",
"ArrayList",
"<",
"ArrayList",
"<",
"KeyValue",
">",
">",
">",
"{",
"final",
"Scanner",
"scanner",
";",
"public",
"MetaScanner",
"(",
")",
"{",
"scanner",
"=",
"getScanner",
"(",
"tsdb",
".",
"uidTable",
"(",
")",
")",
";",
"}",
"/**\n * Fetches the next group of rows from the scanner and sets this class as\n * a callback\n * @return The total number of columns deleted after completion\n */",
"public",
"Deferred",
"<",
"Long",
">",
"scan",
"(",
")",
"{",
"return",
"scanner",
".",
"nextRows",
"(",
")",
".",
"addCallbackDeferring",
"(",
"this",
")",
";",
"}",
"@",
"Override",
"public",
"Deferred",
"<",
"Long",
">",
"call",
"(",
"ArrayList",
"<",
"ArrayList",
"<",
"KeyValue",
">",
">",
"rows",
")",
"throws",
"Exception",
"{",
"if",
"(",
"rows",
"==",
"null",
")",
"{",
"result",
".",
"callback",
"(",
"columns",
")",
";",
"return",
"null",
";",
"}",
"for",
"(",
"final",
"ArrayList",
"<",
"KeyValue",
">",
"row",
":",
"rows",
")",
"{",
"// one delete request per row. We'll almost always delete the whole",
"// row, so preallocate some ram.",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
"qualifiers",
"=",
"new",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
"(",
"row",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"KeyValue",
"column",
":",
"row",
")",
"{",
"if",
"(",
"Bytes",
".",
"equals",
"(",
"TSMeta",
".",
"META_QUALIFIER",
"(",
")",
",",
"column",
".",
"qualifier",
"(",
")",
")",
")",
"{",
"qualifiers",
".",
"add",
"(",
"column",
".",
"qualifier",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"Bytes",
".",
"equals",
"(",
"\"metric_meta\"",
".",
"getBytes",
"(",
"CHARSET",
")",
",",
"column",
".",
"qualifier",
"(",
")",
")",
")",
"{",
"qualifiers",
".",
"add",
"(",
"column",
".",
"qualifier",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"Bytes",
".",
"equals",
"(",
"\"tagk_meta\"",
".",
"getBytes",
"(",
"CHARSET",
")",
",",
"column",
".",
"qualifier",
"(",
")",
")",
")",
"{",
"qualifiers",
".",
"add",
"(",
"column",
".",
"qualifier",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"Bytes",
".",
"equals",
"(",
"\"tagv_meta\"",
".",
"getBytes",
"(",
"CHARSET",
")",
",",
"column",
".",
"qualifier",
"(",
")",
")",
")",
"{",
"qualifiers",
".",
"add",
"(",
"column",
".",
"qualifier",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"qualifiers",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"columns",
"+=",
"qualifiers",
".",
"size",
"(",
")",
";",
"final",
"DeleteRequest",
"delete",
"=",
"new",
"DeleteRequest",
"(",
"tsdb",
".",
"uidTable",
"(",
")",
",",
"row",
".",
"get",
"(",
"0",
")",
".",
"key",
"(",
")",
",",
"NAME_FAMILY",
",",
"qualifiers",
".",
"toArray",
"(",
"new",
"byte",
"[",
"qualifiers",
".",
"size",
"(",
")",
"]",
"[",
"",
"]",
")",
")",
";",
"delete_calls",
".",
"add",
"(",
"tsdb",
".",
"getClient",
"(",
")",
".",
"delete",
"(",
"delete",
")",
")",
";",
"}",
"}",
"/**\n * Buffer callback used to wait on all of the delete calls for the\n * last set of rows returned from the scanner so we don't fill up the\n * deferreds array and OOM out.\n */",
"final",
"class",
"ContinueCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"Long",
">",
",",
"ArrayList",
"<",
"Object",
">",
">",
"{",
"@",
"Override",
"public",
"Deferred",
"<",
"Long",
">",
"call",
"(",
"ArrayList",
"<",
"Object",
">",
"deletes",
")",
"throws",
"Exception",
"{",
"LOG",
".",
"debug",
"(",
"\"[\"",
"+",
"thread_id",
"+",
"\"] Processed [\"",
"+",
"deletes",
".",
"size",
"(",
")",
"+",
"\"] delete calls\"",
")",
";",
"delete_calls",
".",
"clear",
"(",
")",
";",
"return",
"scan",
"(",
")",
";",
"}",
"}",
"// fetch the next set of rows after waiting for current set of delete",
"// requests to complete",
"Deferred",
".",
"group",
"(",
"delete_calls",
")",
".",
"addCallbackDeferring",
"(",
"new",
"ContinueCB",
"(",
")",
")",
";",
"return",
"null",
";",
"}",
"}",
"// start the scan",
"new",
"MetaScanner",
"(",
")",
".",
"scan",
"(",
")",
";",
"return",
"result",
";",
"}"
] |
Scans the entire UID table and removes any UIDMeta objects found.
@return The total number of columns deleted
|
[
"Scans",
"the",
"entire",
"UID",
"table",
"and",
"removes",
"any",
"UIDMeta",
"objects",
"found",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/MetaPurge.java#L101-L199
|
13,726
|
OpenTSDB/opentsdb
|
src/tools/MetaPurge.java
|
MetaPurge.getScanner
|
private Scanner getScanner(final byte[] table) throws HBaseException {
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(table);
scanner.setStartKey(start_row);
scanner.setStopKey(end_row);
scanner.setFamily(NAME_FAMILY);
return scanner;
}
|
java
|
private Scanner getScanner(final byte[] table) throws HBaseException {
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(table);
scanner.setStartKey(start_row);
scanner.setStopKey(end_row);
scanner.setFamily(NAME_FAMILY);
return scanner;
}
|
[
"private",
"Scanner",
"getScanner",
"(",
"final",
"byte",
"[",
"]",
"table",
")",
"throws",
"HBaseException",
"{",
"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",
"(",
"table",
")",
";",
"scanner",
".",
"setStartKey",
"(",
"start_row",
")",
";",
"scanner",
".",
"setStopKey",
"(",
"end_row",
")",
";",
"scanner",
".",
"setFamily",
"(",
"NAME_FAMILY",
")",
";",
"return",
"scanner",
";",
"}"
] |
Returns a scanner to run over the UID table starting at the given row
@return A scanner configured for the entire table
@throws HBaseException if something goes boom
|
[
"Returns",
"a",
"scanner",
"to",
"run",
"over",
"the",
"UID",
"table",
"starting",
"at",
"the",
"given",
"row"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/MetaPurge.java#L304-L315
|
13,727
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.mainUsage
|
public static void mainUsage(PrintStream ps) {
StringBuilder b = new StringBuilder("\nUsage: java -jar [opentsdb.jar] [command] [args]\nValid commands:")
.append("\n\ttsd: Starts a new TSDB instance")
.append("\n\tfsck: Searches for and optionally fixes corrupted data in a TSDB")
.append("\n\timport: Imports data from a file into HBase through a TSDB")
.append("\n\tmkmetric: Creates a new metric")
.append("\n\tquery: Queries time series data from a TSDB ")
.append("\n\tscan: Dumps data straight from HBase")
.append("\n\tuid: Provides various functions to search or modify information in the tsdb-uid table. ")
.append("\n\texportui: Exports the OpenTSDB UI static content")
.append("\n\n\tUse help <command> for details on a command\n");
ps.println(b);
}
|
java
|
public static void mainUsage(PrintStream ps) {
StringBuilder b = new StringBuilder("\nUsage: java -jar [opentsdb.jar] [command] [args]\nValid commands:")
.append("\n\ttsd: Starts a new TSDB instance")
.append("\n\tfsck: Searches for and optionally fixes corrupted data in a TSDB")
.append("\n\timport: Imports data from a file into HBase through a TSDB")
.append("\n\tmkmetric: Creates a new metric")
.append("\n\tquery: Queries time series data from a TSDB ")
.append("\n\tscan: Dumps data straight from HBase")
.append("\n\tuid: Provides various functions to search or modify information in the tsdb-uid table. ")
.append("\n\texportui: Exports the OpenTSDB UI static content")
.append("\n\n\tUse help <command> for details on a command\n");
ps.println(b);
}
|
[
"public",
"static",
"void",
"mainUsage",
"(",
"PrintStream",
"ps",
")",
"{",
"StringBuilder",
"b",
"=",
"new",
"StringBuilder",
"(",
"\"\\nUsage: java -jar [opentsdb.jar] [command] [args]\\nValid commands:\"",
")",
".",
"append",
"(",
"\"\\n\\ttsd: Starts a new TSDB instance\"",
")",
".",
"append",
"(",
"\"\\n\\tfsck: Searches for and optionally fixes corrupted data in a TSDB\"",
")",
".",
"append",
"(",
"\"\\n\\timport: Imports data from a file into HBase through a TSDB\"",
")",
".",
"append",
"(",
"\"\\n\\tmkmetric: Creates a new metric\"",
")",
".",
"append",
"(",
"\"\\n\\tquery: Queries time series data from a TSDB \"",
")",
".",
"append",
"(",
"\"\\n\\tscan: Dumps data straight from HBase\"",
")",
".",
"append",
"(",
"\"\\n\\tuid: Provides various functions to search or modify information in the tsdb-uid table. \"",
")",
".",
"append",
"(",
"\"\\n\\texportui: Exports the OpenTSDB UI static content\"",
")",
".",
"append",
"(",
"\"\\n\\n\\tUse help <command> for details on a command\\n\"",
")",
";",
"ps",
".",
"println",
"(",
"b",
")",
";",
"}"
] |
Prints the main usage banner
|
[
"Prints",
"the",
"main",
"usage",
"banner"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L106-L118
|
13,728
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.main
|
public static void main(String[] args) {
log.info("Starting.");
log.info(BuildData.revisionString());
log.info(BuildData.buildString());
try {
System.in.close(); // Release a FD we don't need.
} catch (Exception e) {
log.warn("Failed to close stdin", e);
}
if(args.length==0) {
log.error("No command supplied");
mainUsage(System.err);
System.exit(-1);
}
// This is not normally needed since values passed on the CL are auto-trimmed,
// but since the Main may be called programatically in some embedded scenarios,
// let's save us some time and trim the values here.
for(int i = 0; i < args.length; i++) {
args[i] = args[i].trim();
}
String targetTool = args[0].toLowerCase();
if(!COMMANDS.containsKey(targetTool)) {
log.error("Command not recognized: [" + targetTool + "]");
mainUsage(System.err);
System.exit(-1);
}
process(targetTool, shift(args));
}
|
java
|
public static void main(String[] args) {
log.info("Starting.");
log.info(BuildData.revisionString());
log.info(BuildData.buildString());
try {
System.in.close(); // Release a FD we don't need.
} catch (Exception e) {
log.warn("Failed to close stdin", e);
}
if(args.length==0) {
log.error("No command supplied");
mainUsage(System.err);
System.exit(-1);
}
// This is not normally needed since values passed on the CL are auto-trimmed,
// but since the Main may be called programatically in some embedded scenarios,
// let's save us some time and trim the values here.
for(int i = 0; i < args.length; i++) {
args[i] = args[i].trim();
}
String targetTool = args[0].toLowerCase();
if(!COMMANDS.containsKey(targetTool)) {
log.error("Command not recognized: [" + targetTool + "]");
mainUsage(System.err);
System.exit(-1);
}
process(targetTool, shift(args));
}
|
[
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"log",
".",
"info",
"(",
"\"Starting.\"",
")",
";",
"log",
".",
"info",
"(",
"BuildData",
".",
"revisionString",
"(",
")",
")",
";",
"log",
".",
"info",
"(",
"BuildData",
".",
"buildString",
"(",
")",
")",
";",
"try",
"{",
"System",
".",
"in",
".",
"close",
"(",
")",
";",
"// Release a FD we don't need.",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"log",
".",
"warn",
"(",
"\"Failed to close stdin\"",
",",
"e",
")",
";",
"}",
"if",
"(",
"args",
".",
"length",
"==",
"0",
")",
"{",
"log",
".",
"error",
"(",
"\"No command supplied\"",
")",
";",
"mainUsage",
"(",
"System",
".",
"err",
")",
";",
"System",
".",
"exit",
"(",
"-",
"1",
")",
";",
"}",
"// This is not normally needed since values passed on the CL are auto-trimmed,",
"// but since the Main may be called programatically in some embedded scenarios,",
"// let's save us some time and trim the values here.",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"args",
"[",
"i",
"]",
"=",
"args",
"[",
"i",
"]",
".",
"trim",
"(",
")",
";",
"}",
"String",
"targetTool",
"=",
"args",
"[",
"0",
"]",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"!",
"COMMANDS",
".",
"containsKey",
"(",
"targetTool",
")",
")",
"{",
"log",
".",
"error",
"(",
"\"Command not recognized: [\"",
"+",
"targetTool",
"+",
"\"]\"",
")",
";",
"mainUsage",
"(",
"System",
".",
"err",
")",
";",
"System",
".",
"exit",
"(",
"-",
"1",
")",
";",
"}",
"process",
"(",
"targetTool",
",",
"shift",
"(",
"args",
")",
")",
";",
"}"
] |
The OpenTSDB fat-jar main entry point
@param args See usage banner {@link OpenTSDBMain#mainUsage(PrintStream)}
|
[
"The",
"OpenTSDB",
"fat",
"-",
"jar",
"main",
"entry",
"point"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L125-L152
|
13,729
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.process
|
private static void process(String targetTool, String[] args) {
if("mkmetric".equals(targetTool)) {
shift(args);
}
if(!"tsd".equals(targetTool)) {
try {
COMMANDS.get(targetTool).getDeclaredMethod("main", String[].class).invoke(null, new Object[] {args});
} catch(Exception x) {
log.error("Failed to call [" + targetTool + "].", x);
System.exit(-1);
}
} else {
launchTSD(args);
}
}
|
java
|
private static void process(String targetTool, String[] args) {
if("mkmetric".equals(targetTool)) {
shift(args);
}
if(!"tsd".equals(targetTool)) {
try {
COMMANDS.get(targetTool).getDeclaredMethod("main", String[].class).invoke(null, new Object[] {args});
} catch(Exception x) {
log.error("Failed to call [" + targetTool + "].", x);
System.exit(-1);
}
} else {
launchTSD(args);
}
}
|
[
"private",
"static",
"void",
"process",
"(",
"String",
"targetTool",
",",
"String",
"[",
"]",
"args",
")",
"{",
"if",
"(",
"\"mkmetric\"",
".",
"equals",
"(",
"targetTool",
")",
")",
"{",
"shift",
"(",
"args",
")",
";",
"}",
"if",
"(",
"!",
"\"tsd\"",
".",
"equals",
"(",
"targetTool",
")",
")",
"{",
"try",
"{",
"COMMANDS",
".",
"get",
"(",
"targetTool",
")",
".",
"getDeclaredMethod",
"(",
"\"main\"",
",",
"String",
"[",
"]",
".",
"class",
")",
".",
"invoke",
"(",
"null",
",",
"new",
"Object",
"[",
"]",
"{",
"args",
"}",
")",
";",
"}",
"catch",
"(",
"Exception",
"x",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to call [\"",
"+",
"targetTool",
"+",
"\"].\"",
",",
"x",
")",
";",
"System",
".",
"exit",
"(",
"-",
"1",
")",
";",
"}",
"}",
"else",
"{",
"launchTSD",
"(",
"args",
")",
";",
"}",
"}"
] |
Executes the target tool
@param targetTool the name of the target tool to execute
@param args The command line arguments minus the tool name
|
[
"Executes",
"the",
"target",
"tool"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L159-L173
|
13,730
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.applyCommandLine
|
protected static void applyCommandLine(ConfigArgP cap, ArgP argp) {
// --config, --include-config, --help
if(argp.has("--help")) {
if(cap.hasNonOption("extended")) {
System.out.println(cap.getExtendedUsage("tsd extended usage:"));
} else {
System.out.println(cap.getDefaultUsage("tsd usage:"));
}
System.exit(0);
}
if(argp.has("--config")) {
loadConfigSource(cap, argp.get("--config").trim());
}
if(argp.has("--include")) {
String[] sources = argp.get("--include").split(",");
for(String s: sources) {
loadConfigSource(cap, s.trim());
}
}
}
|
java
|
protected static void applyCommandLine(ConfigArgP cap, ArgP argp) {
// --config, --include-config, --help
if(argp.has("--help")) {
if(cap.hasNonOption("extended")) {
System.out.println(cap.getExtendedUsage("tsd extended usage:"));
} else {
System.out.println(cap.getDefaultUsage("tsd usage:"));
}
System.exit(0);
}
if(argp.has("--config")) {
loadConfigSource(cap, argp.get("--config").trim());
}
if(argp.has("--include")) {
String[] sources = argp.get("--include").split(",");
for(String s: sources) {
loadConfigSource(cap, s.trim());
}
}
}
|
[
"protected",
"static",
"void",
"applyCommandLine",
"(",
"ConfigArgP",
"cap",
",",
"ArgP",
"argp",
")",
"{",
"// --config, --include-config, --help",
"if",
"(",
"argp",
".",
"has",
"(",
"\"--help\"",
")",
")",
"{",
"if",
"(",
"cap",
".",
"hasNonOption",
"(",
"\"extended\"",
")",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"cap",
".",
"getExtendedUsage",
"(",
"\"tsd extended usage:\"",
")",
")",
";",
"}",
"else",
"{",
"System",
".",
"out",
".",
"println",
"(",
"cap",
".",
"getDefaultUsage",
"(",
"\"tsd usage:\"",
")",
")",
";",
"}",
"System",
".",
"exit",
"(",
"0",
")",
";",
"}",
"if",
"(",
"argp",
".",
"has",
"(",
"\"--config\"",
")",
")",
"{",
"loadConfigSource",
"(",
"cap",
",",
"argp",
".",
"get",
"(",
"\"--config\"",
")",
".",
"trim",
"(",
")",
")",
";",
"}",
"if",
"(",
"argp",
".",
"has",
"(",
"\"--include\"",
")",
")",
"{",
"String",
"[",
"]",
"sources",
"=",
"argp",
".",
"get",
"(",
"\"--include\"",
")",
".",
"split",
"(",
"\",\"",
")",
";",
"for",
"(",
"String",
"s",
":",
"sources",
")",
"{",
"loadConfigSource",
"(",
"cap",
",",
"s",
".",
"trim",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
Applies and processes the pre-tsd command line
@param cap The main configuration wrapper
@param argp The preped command line argument handler
|
[
"Applies",
"and",
"processes",
"the",
"pre",
"-",
"tsd",
"command",
"line"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L181-L200
|
13,731
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.setJVMName
|
protected static void setJVMName(final int port, final String iface) {
final Properties p = getAgentProperties();
if(p!=null) {
final String ifc = (iface==null || iface.trim().isEmpty()) ? "" : (iface.trim() + ":");
final String name = "opentsdb[" + ifc + port + "]";
p.setProperty("sun.java.command", name);
p.setProperty("sun.rt.javaCommand", name);
System.setProperty("sun.java.command", name);
System.setProperty("sun.rt.javaCommand", name);
}
}
|
java
|
protected static void setJVMName(final int port, final String iface) {
final Properties p = getAgentProperties();
if(p!=null) {
final String ifc = (iface==null || iface.trim().isEmpty()) ? "" : (iface.trim() + ":");
final String name = "opentsdb[" + ifc + port + "]";
p.setProperty("sun.java.command", name);
p.setProperty("sun.rt.javaCommand", name);
System.setProperty("sun.java.command", name);
System.setProperty("sun.rt.javaCommand", name);
}
}
|
[
"protected",
"static",
"void",
"setJVMName",
"(",
"final",
"int",
"port",
",",
"final",
"String",
"iface",
")",
"{",
"final",
"Properties",
"p",
"=",
"getAgentProperties",
"(",
")",
";",
"if",
"(",
"p",
"!=",
"null",
")",
"{",
"final",
"String",
"ifc",
"=",
"(",
"iface",
"==",
"null",
"||",
"iface",
".",
"trim",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"?",
"\"\"",
":",
"(",
"iface",
".",
"trim",
"(",
")",
"+",
"\":\"",
")",
";",
"final",
"String",
"name",
"=",
"\"opentsdb[\"",
"+",
"ifc",
"+",
"port",
"+",
"\"]\"",
";",
"p",
".",
"setProperty",
"(",
"\"sun.java.command\"",
",",
"name",
")",
";",
"p",
".",
"setProperty",
"(",
"\"sun.rt.javaCommand\"",
",",
"name",
")",
";",
"System",
".",
"setProperty",
"(",
"\"sun.java.command\"",
",",
"name",
")",
";",
"System",
".",
"setProperty",
"(",
"\"sun.rt.javaCommand\"",
",",
"name",
")",
";",
"}",
"}"
] |
Attempts to set the vm agent property that identifies the vm's display name.
This is the name displayed for tools such as jconsole and jps when using auto-dicsovery.
When using a fat-jar, this provides a much more identifiable name
@param port The listening port
@param iface The bound interface
|
[
"Attempts",
"to",
"set",
"the",
"vm",
"agent",
"property",
"that",
"identifies",
"the",
"vm",
"s",
"display",
"name",
".",
"This",
"is",
"the",
"name",
"displayed",
"for",
"tools",
"such",
"as",
"jconsole",
"and",
"jps",
"when",
"using",
"auto",
"-",
"dicsovery",
".",
"When",
"using",
"a",
"fat",
"-",
"jar",
"this",
"provides",
"a",
"much",
"more",
"identifiable",
"name"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L449-L459
|
13,732
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.getAgentProperties
|
protected static Properties getAgentProperties() {
try {
Class<?> clazz = Class.forName("sun.misc.VMSupport");
Method m = clazz.getDeclaredMethod("getAgentProperties");
m.setAccessible(true);
Properties p = (Properties)m.invoke(null);
return p;
} catch (Throwable t) {
return null;
}
}
|
java
|
protected static Properties getAgentProperties() {
try {
Class<?> clazz = Class.forName("sun.misc.VMSupport");
Method m = clazz.getDeclaredMethod("getAgentProperties");
m.setAccessible(true);
Properties p = (Properties)m.invoke(null);
return p;
} catch (Throwable t) {
return null;
}
}
|
[
"protected",
"static",
"Properties",
"getAgentProperties",
"(",
")",
"{",
"try",
"{",
"Class",
"<",
"?",
">",
"clazz",
"=",
"Class",
".",
"forName",
"(",
"\"sun.misc.VMSupport\"",
")",
";",
"Method",
"m",
"=",
"clazz",
".",
"getDeclaredMethod",
"(",
"\"getAgentProperties\"",
")",
";",
"m",
".",
"setAccessible",
"(",
"true",
")",
";",
"Properties",
"p",
"=",
"(",
"Properties",
")",
"m",
".",
"invoke",
"(",
"null",
")",
";",
"return",
"p",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the agent properties
@return the agent properties or null if reflective call failed
|
[
"Returns",
"the",
"agent",
"properties"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L465-L475
|
13,733
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.insertPattern
|
protected static String insertPattern(final String logFileName, final String rollPattern) {
int index = logFileName.lastIndexOf('.');
if(index==-1) return logFileName + rollPattern;
return logFileName.substring(0, index) + rollPattern + logFileName.substring(index);
}
|
java
|
protected static String insertPattern(final String logFileName, final String rollPattern) {
int index = logFileName.lastIndexOf('.');
if(index==-1) return logFileName + rollPattern;
return logFileName.substring(0, index) + rollPattern + logFileName.substring(index);
}
|
[
"protected",
"static",
"String",
"insertPattern",
"(",
"final",
"String",
"logFileName",
",",
"final",
"String",
"rollPattern",
")",
"{",
"int",
"index",
"=",
"logFileName",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"index",
"==",
"-",
"1",
")",
"return",
"logFileName",
"+",
"rollPattern",
";",
"return",
"logFileName",
".",
"substring",
"(",
"0",
",",
"index",
")",
"+",
"rollPattern",
"+",
"logFileName",
".",
"substring",
"(",
"index",
")",
";",
"}"
] |
Merges the roll pattern name into the file name
@param logFileName The log file name
@param rollPattern The rolling log file appender roll pattern
@return the merged file pattern
|
[
"Merges",
"the",
"roll",
"pattern",
"name",
"into",
"the",
"file",
"name"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L526-L530
|
13,734
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.setLogbackExternal
|
protected static void setLogbackExternal(final String fileName) {
try {
final ObjectName logbackObjectName = new ObjectName("ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator");
ManagementFactory.getPlatformMBeanServer().invoke(logbackObjectName, "reloadByFileName", new Object[]{fileName}, new String[]{String.class.getName()});
log.info("Set external logback config to [{}]", fileName);
} catch (Exception ex) {
log.warn("Failed to set external logback config to [{}]", fileName, ex);
}
}
|
java
|
protected static void setLogbackExternal(final String fileName) {
try {
final ObjectName logbackObjectName = new ObjectName("ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator");
ManagementFactory.getPlatformMBeanServer().invoke(logbackObjectName, "reloadByFileName", new Object[]{fileName}, new String[]{String.class.getName()});
log.info("Set external logback config to [{}]", fileName);
} catch (Exception ex) {
log.warn("Failed to set external logback config to [{}]", fileName, ex);
}
}
|
[
"protected",
"static",
"void",
"setLogbackExternal",
"(",
"final",
"String",
"fileName",
")",
"{",
"try",
"{",
"final",
"ObjectName",
"logbackObjectName",
"=",
"new",
"ObjectName",
"(",
"\"ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator\"",
")",
";",
"ManagementFactory",
".",
"getPlatformMBeanServer",
"(",
")",
".",
"invoke",
"(",
"logbackObjectName",
",",
"\"reloadByFileName\"",
",",
"new",
"Object",
"[",
"]",
"{",
"fileName",
"}",
",",
"new",
"String",
"[",
"]",
"{",
"String",
".",
"class",
".",
"getName",
"(",
")",
"}",
")",
";",
"log",
".",
"info",
"(",
"\"Set external logback config to [{}]\"",
",",
"fileName",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"log",
".",
"warn",
"(",
"\"Failed to set external logback config to [{}]\"",
",",
"fileName",
",",
"ex",
")",
";",
"}",
"}"
] |
Reloads the logback configuration to an external file
@param fileName The logback configuration file
|
[
"Reloads",
"the",
"logback",
"configuration",
"to",
"an",
"external",
"file"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L537-L545
|
13,735
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.shift
|
private static String[] shift(String[] args) {
if(args==null || args.length==0 | args.length==1) return new String[0];
String[] newArgs = new String[args.length-1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
return newArgs;
}
|
java
|
private static String[] shift(String[] args) {
if(args==null || args.length==0 | args.length==1) return new String[0];
String[] newArgs = new String[args.length-1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
return newArgs;
}
|
[
"private",
"static",
"String",
"[",
"]",
"shift",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"if",
"(",
"args",
"==",
"null",
"||",
"args",
".",
"length",
"==",
"0",
"|",
"args",
".",
"length",
"==",
"1",
")",
"return",
"new",
"String",
"[",
"0",
"]",
";",
"String",
"[",
"]",
"newArgs",
"=",
"new",
"String",
"[",
"args",
".",
"length",
"-",
"1",
"]",
";",
"System",
".",
"arraycopy",
"(",
"args",
",",
"1",
",",
"newArgs",
",",
"0",
",",
"newArgs",
".",
"length",
")",
";",
"return",
"newArgs",
";",
"}"
] |
Drops the first array item in the passed array.
If the passed array is null or empty, returns an empty array
@param args The array to shift
@return the shifted array
|
[
"Drops",
"the",
"first",
"array",
"item",
"in",
"the",
"passed",
"array",
".",
"If",
"the",
"passed",
"array",
"is",
"null",
"or",
"empty",
"returns",
"an",
"empty",
"array"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L554-L559
|
13,736
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.writePid
|
private static void writePid(String file, boolean ignorePidFile) {
File pidFile = new File(file);
if(pidFile.exists()) {
Long oldPid = getPid(pidFile);
if(oldPid==null) {
pidFile.delete();
} else {
log.warn("\n\t==================================\n\tThe OpenTSDB PID file [" + file + "] already exists for PID [" + oldPid + "]. \n\tOpenTSDB might already be running.\n\t==================================\n");
if(!ignorePidFile) {
log.warn("Exiting due to existing pid file. Start with option --ignore-existing-pid to overwrite");
System.exit(-1);
} else {
log.warn("Deleting existing pid file [" + file + "]");
pidFile.delete();
}
}
}
pidFile.deleteOnExit();
File pidDir = pidFile.getParentFile();
FileOutputStream fos = null;
try {
if(!pidDir.exists()) {
if(!pidDir.mkdirs()) {
throw new Exception("Failed to create PID directory [" + file + "]");
}
}
fos = new FileOutputStream(pidFile);
String PID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
fos.write(String.format("%s%s", PID, EOL).getBytes());
fos.flush();
fos.close();
fos = null;
log.info("PID [" + PID + "] written to pid file [" + file + "]");
} catch (Exception ex) {
log.error("Failed to write PID file to [" + file + "]", ex);
throw new IllegalArgumentException("Failed to write PID file to [" + file + "]", ex);
} finally {
if(fos!=null) try { fos.close(); } catch (Exception ex) { /* No Op */ }
}
}
|
java
|
private static void writePid(String file, boolean ignorePidFile) {
File pidFile = new File(file);
if(pidFile.exists()) {
Long oldPid = getPid(pidFile);
if(oldPid==null) {
pidFile.delete();
} else {
log.warn("\n\t==================================\n\tThe OpenTSDB PID file [" + file + "] already exists for PID [" + oldPid + "]. \n\tOpenTSDB might already be running.\n\t==================================\n");
if(!ignorePidFile) {
log.warn("Exiting due to existing pid file. Start with option --ignore-existing-pid to overwrite");
System.exit(-1);
} else {
log.warn("Deleting existing pid file [" + file + "]");
pidFile.delete();
}
}
}
pidFile.deleteOnExit();
File pidDir = pidFile.getParentFile();
FileOutputStream fos = null;
try {
if(!pidDir.exists()) {
if(!pidDir.mkdirs()) {
throw new Exception("Failed to create PID directory [" + file + "]");
}
}
fos = new FileOutputStream(pidFile);
String PID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
fos.write(String.format("%s%s", PID, EOL).getBytes());
fos.flush();
fos.close();
fos = null;
log.info("PID [" + PID + "] written to pid file [" + file + "]");
} catch (Exception ex) {
log.error("Failed to write PID file to [" + file + "]", ex);
throw new IllegalArgumentException("Failed to write PID file to [" + file + "]", ex);
} finally {
if(fos!=null) try { fos.close(); } catch (Exception ex) { /* No Op */ }
}
}
|
[
"private",
"static",
"void",
"writePid",
"(",
"String",
"file",
",",
"boolean",
"ignorePidFile",
")",
"{",
"File",
"pidFile",
"=",
"new",
"File",
"(",
"file",
")",
";",
"if",
"(",
"pidFile",
".",
"exists",
"(",
")",
")",
"{",
"Long",
"oldPid",
"=",
"getPid",
"(",
"pidFile",
")",
";",
"if",
"(",
"oldPid",
"==",
"null",
")",
"{",
"pidFile",
".",
"delete",
"(",
")",
";",
"}",
"else",
"{",
"log",
".",
"warn",
"(",
"\"\\n\\t==================================\\n\\tThe OpenTSDB PID file [\"",
"+",
"file",
"+",
"\"] already exists for PID [\"",
"+",
"oldPid",
"+",
"\"]. \\n\\tOpenTSDB might already be running.\\n\\t==================================\\n\"",
")",
";",
"if",
"(",
"!",
"ignorePidFile",
")",
"{",
"log",
".",
"warn",
"(",
"\"Exiting due to existing pid file. Start with option --ignore-existing-pid to overwrite\"",
")",
";",
"System",
".",
"exit",
"(",
"-",
"1",
")",
";",
"}",
"else",
"{",
"log",
".",
"warn",
"(",
"\"Deleting existing pid file [\"",
"+",
"file",
"+",
"\"]\"",
")",
";",
"pidFile",
".",
"delete",
"(",
")",
";",
"}",
"}",
"}",
"pidFile",
".",
"deleteOnExit",
"(",
")",
";",
"File",
"pidDir",
"=",
"pidFile",
".",
"getParentFile",
"(",
")",
";",
"FileOutputStream",
"fos",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"!",
"pidDir",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"!",
"pidDir",
".",
"mkdirs",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Failed to create PID directory [\"",
"+",
"file",
"+",
"\"]\"",
")",
";",
"}",
"}",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"pidFile",
")",
";",
"String",
"PID",
"=",
"ManagementFactory",
".",
"getRuntimeMXBean",
"(",
")",
".",
"getName",
"(",
")",
".",
"split",
"(",
"\"@\"",
")",
"[",
"0",
"]",
";",
"fos",
".",
"write",
"(",
"String",
".",
"format",
"(",
"\"%s%s\"",
",",
"PID",
",",
"EOL",
")",
".",
"getBytes",
"(",
")",
")",
";",
"fos",
".",
"flush",
"(",
")",
";",
"fos",
".",
"close",
"(",
")",
";",
"fos",
"=",
"null",
";",
"log",
".",
"info",
"(",
"\"PID [\"",
"+",
"PID",
"+",
"\"] written to pid file [\"",
"+",
"file",
"+",
"\"]\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to write PID file to [\"",
"+",
"file",
"+",
"\"]\"",
",",
"ex",
")",
";",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Failed to write PID file to [\"",
"+",
"file",
"+",
"\"]\"",
",",
"ex",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"fos",
"!=",
"null",
")",
"try",
"{",
"fos",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"/* No Op */",
"}",
"}",
"}"
] |
Writes the PID to the file at the passed location
@param file The fully qualified pid file name
@param ignorePidFile If true, an existing pid file will be ignored after a warning log
|
[
"Writes",
"the",
"PID",
"to",
"the",
"file",
"at",
"the",
"passed",
"location"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L797-L836
|
13,737
|
OpenTSDB/opentsdb
|
src/tools/OpenTSDBMain.java
|
OpenTSDBMain.getPid
|
private static Long getPid(File pidFile) {
FileReader reader = null;
BufferedReader lineReader = null;
String pidLine = null;
try {
reader = new FileReader(pidFile);
lineReader = new BufferedReader(reader);
pidLine = lineReader.readLine();
if(pidLine!=null) {
pidLine = pidLine.trim();
}
} catch (Exception ex) {
log.error("Failed to read PID from file [" + pidFile.getAbsolutePath() + "]", ex);
} finally {
if(reader!=null) try { reader.close(); } catch (Exception ex) { /* No Op */ }
}
try {
return Long.parseLong(pidLine);
} catch (Exception ex) {
return null;
}
}
|
java
|
private static Long getPid(File pidFile) {
FileReader reader = null;
BufferedReader lineReader = null;
String pidLine = null;
try {
reader = new FileReader(pidFile);
lineReader = new BufferedReader(reader);
pidLine = lineReader.readLine();
if(pidLine!=null) {
pidLine = pidLine.trim();
}
} catch (Exception ex) {
log.error("Failed to read PID from file [" + pidFile.getAbsolutePath() + "]", ex);
} finally {
if(reader!=null) try { reader.close(); } catch (Exception ex) { /* No Op */ }
}
try {
return Long.parseLong(pidLine);
} catch (Exception ex) {
return null;
}
}
|
[
"private",
"static",
"Long",
"getPid",
"(",
"File",
"pidFile",
")",
"{",
"FileReader",
"reader",
"=",
"null",
";",
"BufferedReader",
"lineReader",
"=",
"null",
";",
"String",
"pidLine",
"=",
"null",
";",
"try",
"{",
"reader",
"=",
"new",
"FileReader",
"(",
"pidFile",
")",
";",
"lineReader",
"=",
"new",
"BufferedReader",
"(",
"reader",
")",
";",
"pidLine",
"=",
"lineReader",
".",
"readLine",
"(",
")",
";",
"if",
"(",
"pidLine",
"!=",
"null",
")",
"{",
"pidLine",
"=",
"pidLine",
".",
"trim",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to read PID from file [\"",
"+",
"pidFile",
".",
"getAbsolutePath",
"(",
")",
"+",
"\"]\"",
",",
"ex",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"reader",
"!=",
"null",
")",
"try",
"{",
"reader",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"/* No Op */",
"}",
"}",
"try",
"{",
"return",
"Long",
".",
"parseLong",
"(",
"pidLine",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Reads the pid from the specified pid file
@param pidFile The pid file to read from
@return The read pid or possibly null / blank if failed to read
|
[
"Reads",
"the",
"pid",
"from",
"the",
"specified",
"pid",
"file"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/OpenTSDBMain.java#L843-L864
|
13,738
|
OpenTSDB/opentsdb
|
src/core/HistogramSpan.java
|
HistogramSpan.getIdxOffsetFor
|
private long getIdxOffsetFor(final int i) {
checkRowOrder();
int idx = 0;
int offset = 0;
for (final iHistogramRowSeq row : rows) {
final int sz = row.size();
if (offset + sz > i) {
break;
}
offset += sz;
idx++;
}
return ((long) idx << 32) | (i - offset);
}
|
java
|
private long getIdxOffsetFor(final int i) {
checkRowOrder();
int idx = 0;
int offset = 0;
for (final iHistogramRowSeq row : rows) {
final int sz = row.size();
if (offset + sz > i) {
break;
}
offset += sz;
idx++;
}
return ((long) idx << 32) | (i - offset);
}
|
[
"private",
"long",
"getIdxOffsetFor",
"(",
"final",
"int",
"i",
")",
"{",
"checkRowOrder",
"(",
")",
";",
"int",
"idx",
"=",
"0",
";",
"int",
"offset",
"=",
"0",
";",
"for",
"(",
"final",
"iHistogramRowSeq",
"row",
":",
"rows",
")",
"{",
"final",
"int",
"sz",
"=",
"row",
".",
"size",
"(",
")",
";",
"if",
"(",
"offset",
"+",
"sz",
">",
"i",
")",
"{",
"break",
";",
"}",
"offset",
"+=",
"sz",
";",
"idx",
"++",
";",
"}",
"return",
"(",
"(",
"long",
")",
"idx",
"<<",
"32",
")",
"|",
"(",
"i",
"-",
"offset",
")",
";",
"}"
] |
Finds the index of the row of the ith data point and the offset in the row.
@param i The index of the data point to find.
@return two ints packed in a long. The first int is the index of the row in
{@code rows} and the second is offset in that {@link RowSeq}
instance.
|
[
"Finds",
"the",
"index",
"of",
"the",
"row",
"of",
"the",
"ith",
"data",
"point",
"and",
"the",
"offset",
"in",
"the",
"row",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/HistogramSpan.java#L360-L373
|
13,739
|
OpenTSDB/opentsdb
|
src/query/pojo/Timespan.java
|
Timespan.validate
|
public void validate() {
if (start == null || start.isEmpty()) {
throw new IllegalArgumentException("missing or empty start");
}
DateTime.parseDateTimeString(start, timezone);
if (end != null && !end.isEmpty()) {
DateTime.parseDateTimeString(end, timezone);
}
if (downsampler != null) {
downsampler.validate();
}
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");
}
}
|
java
|
public void validate() {
if (start == null || start.isEmpty()) {
throw new IllegalArgumentException("missing or empty start");
}
DateTime.parseDateTimeString(start, timezone);
if (end != null && !end.isEmpty()) {
DateTime.parseDateTimeString(end, timezone);
}
if (downsampler != null) {
downsampler.validate();
}
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");
}
}
|
[
"public",
"void",
"validate",
"(",
")",
"{",
"if",
"(",
"start",
"==",
"null",
"||",
"start",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"missing or empty start\"",
")",
";",
"}",
"DateTime",
".",
"parseDateTimeString",
"(",
"start",
",",
"timezone",
")",
";",
"if",
"(",
"end",
"!=",
"null",
"&&",
"!",
"end",
".",
"isEmpty",
"(",
")",
")",
"{",
"DateTime",
".",
"parseDateTimeString",
"(",
"end",
",",
"timezone",
")",
";",
"}",
"if",
"(",
"downsampler",
"!=",
"null",
")",
"{",
"downsampler",
".",
"validate",
"(",
")",
";",
"}",
"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\"",
")",
";",
"}",
"}"
] |
Validates the timespan
@throws IllegalArgumentException if one or more parameters were invalid
|
[
"Validates",
"the",
"timespan"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/pojo/Timespan.java#L124-L147
|
13,740
|
OpenTSDB/opentsdb
|
src/tsd/client/QueryUi.java
|
QueryUi.makeStylePanel
|
private Grid makeStylePanel() {
for (Entry<String, Integer> item : stylesMap.entrySet()) {
styles.insertItem(item.getKey(), item.getValue());
}
final Grid grid = new Grid(5, 3);
grid.setText(0, 1, "Smooth");
grid.setWidget(0, 2, smooth);
grid.setText(1, 1, "Style");
grid.setWidget(1, 2, styles);
return grid;
}
|
java
|
private Grid makeStylePanel() {
for (Entry<String, Integer> item : stylesMap.entrySet()) {
styles.insertItem(item.getKey(), item.getValue());
}
final Grid grid = new Grid(5, 3);
grid.setText(0, 1, "Smooth");
grid.setWidget(0, 2, smooth);
grid.setText(1, 1, "Style");
grid.setWidget(1, 2, styles);
return grid;
}
|
[
"private",
"Grid",
"makeStylePanel",
"(",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"Integer",
">",
"item",
":",
"stylesMap",
".",
"entrySet",
"(",
")",
")",
"{",
"styles",
".",
"insertItem",
"(",
"item",
".",
"getKey",
"(",
")",
",",
"item",
".",
"getValue",
"(",
")",
")",
";",
"}",
"final",
"Grid",
"grid",
"=",
"new",
"Grid",
"(",
"5",
",",
"3",
")",
";",
"grid",
".",
"setText",
"(",
"0",
",",
"1",
",",
"\"Smooth\"",
")",
";",
"grid",
".",
"setWidget",
"(",
"0",
",",
"2",
",",
"smooth",
")",
";",
"grid",
".",
"setText",
"(",
"1",
",",
"1",
",",
"\"Style\"",
")",
";",
"grid",
".",
"setWidget",
"(",
"1",
",",
"2",
",",
"styles",
")",
";",
"return",
"grid",
";",
"}"
] |
Additional styling options.
|
[
"Additional",
"styling",
"options",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryUi.java#L502-L512
|
13,741
|
OpenTSDB/opentsdb
|
src/tsd/client/QueryUi.java
|
QueryUi.makeAxesPanel
|
private Grid makeAxesPanel() {
final Grid grid = new Grid(5, 3);
grid.setText(0, 1, "Y");
grid.setText(0, 2, "Y2");
setTextAlignCenter(grid.getRowFormatter().getElement(0));
grid.setText(1, 0, "Label");
grid.setWidget(1, 1, ylabel);
grid.setWidget(1, 2, y2label);
grid.setText(2, 0, "Format");
grid.setWidget(2, 1, yformat);
grid.setWidget(2, 2, y2format);
grid.setText(3, 0, "Range");
grid.setWidget(3, 1, yrange);
grid.setWidget(3, 2, y2range);
grid.setText(4, 0, "Log scale");
grid.setWidget(4, 1, ylog);
grid.setWidget(4, 2, y2log);
setTextAlignCenter(grid.getCellFormatter().getElement(4, 1));
setTextAlignCenter(grid.getCellFormatter().getElement(4, 2));
return grid;
}
|
java
|
private Grid makeAxesPanel() {
final Grid grid = new Grid(5, 3);
grid.setText(0, 1, "Y");
grid.setText(0, 2, "Y2");
setTextAlignCenter(grid.getRowFormatter().getElement(0));
grid.setText(1, 0, "Label");
grid.setWidget(1, 1, ylabel);
grid.setWidget(1, 2, y2label);
grid.setText(2, 0, "Format");
grid.setWidget(2, 1, yformat);
grid.setWidget(2, 2, y2format);
grid.setText(3, 0, "Range");
grid.setWidget(3, 1, yrange);
grid.setWidget(3, 2, y2range);
grid.setText(4, 0, "Log scale");
grid.setWidget(4, 1, ylog);
grid.setWidget(4, 2, y2log);
setTextAlignCenter(grid.getCellFormatter().getElement(4, 1));
setTextAlignCenter(grid.getCellFormatter().getElement(4, 2));
return grid;
}
|
[
"private",
"Grid",
"makeAxesPanel",
"(",
")",
"{",
"final",
"Grid",
"grid",
"=",
"new",
"Grid",
"(",
"5",
",",
"3",
")",
";",
"grid",
".",
"setText",
"(",
"0",
",",
"1",
",",
"\"Y\"",
")",
";",
"grid",
".",
"setText",
"(",
"0",
",",
"2",
",",
"\"Y2\"",
")",
";",
"setTextAlignCenter",
"(",
"grid",
".",
"getRowFormatter",
"(",
")",
".",
"getElement",
"(",
"0",
")",
")",
";",
"grid",
".",
"setText",
"(",
"1",
",",
"0",
",",
"\"Label\"",
")",
";",
"grid",
".",
"setWidget",
"(",
"1",
",",
"1",
",",
"ylabel",
")",
";",
"grid",
".",
"setWidget",
"(",
"1",
",",
"2",
",",
"y2label",
")",
";",
"grid",
".",
"setText",
"(",
"2",
",",
"0",
",",
"\"Format\"",
")",
";",
"grid",
".",
"setWidget",
"(",
"2",
",",
"1",
",",
"yformat",
")",
";",
"grid",
".",
"setWidget",
"(",
"2",
",",
"2",
",",
"y2format",
")",
";",
"grid",
".",
"setText",
"(",
"3",
",",
"0",
",",
"\"Range\"",
")",
";",
"grid",
".",
"setWidget",
"(",
"3",
",",
"1",
",",
"yrange",
")",
";",
"grid",
".",
"setWidget",
"(",
"3",
",",
"2",
",",
"y2range",
")",
";",
"grid",
".",
"setText",
"(",
"4",
",",
"0",
",",
"\"Log scale\"",
")",
";",
"grid",
".",
"setWidget",
"(",
"4",
",",
"1",
",",
"ylog",
")",
";",
"grid",
".",
"setWidget",
"(",
"4",
",",
"2",
",",
"y2log",
")",
";",
"setTextAlignCenter",
"(",
"grid",
".",
"getCellFormatter",
"(",
")",
".",
"getElement",
"(",
"4",
",",
"1",
")",
")",
";",
"setTextAlignCenter",
"(",
"grid",
".",
"getCellFormatter",
"(",
")",
".",
"getElement",
"(",
"4",
",",
"2",
")",
")",
";",
"return",
"grid",
";",
"}"
] |
Builds the panel containing customizations for the axes of the graph.
|
[
"Builds",
"the",
"panel",
"containing",
"customizations",
"for",
"the",
"axes",
"of",
"the",
"graph",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryUi.java#L517-L537
|
13,742
|
OpenTSDB/opentsdb
|
src/tsd/client/QueryUi.java
|
QueryUi.addKeyRadioButton
|
private RadioButton addKeyRadioButton(final Grid grid,
final int row, final int col,
final String pos) {
final RadioButton rb = new RadioButton("keypos");
rb.addClickHandler(new ClickHandler() {
public void onClick(final ClickEvent event) {
keypos = pos;
}
});
rb.addClickHandler(refreshgraph);
grid.setWidget(row, col, rb);
keypos_map.put(pos, rb);
return rb;
}
|
java
|
private RadioButton addKeyRadioButton(final Grid grid,
final int row, final int col,
final String pos) {
final RadioButton rb = new RadioButton("keypos");
rb.addClickHandler(new ClickHandler() {
public void onClick(final ClickEvent event) {
keypos = pos;
}
});
rb.addClickHandler(refreshgraph);
grid.setWidget(row, col, rb);
keypos_map.put(pos, rb);
return rb;
}
|
[
"private",
"RadioButton",
"addKeyRadioButton",
"(",
"final",
"Grid",
"grid",
",",
"final",
"int",
"row",
",",
"final",
"int",
"col",
",",
"final",
"String",
"pos",
")",
"{",
"final",
"RadioButton",
"rb",
"=",
"new",
"RadioButton",
"(",
"\"keypos\"",
")",
";",
"rb",
".",
"addClickHandler",
"(",
"new",
"ClickHandler",
"(",
")",
"{",
"public",
"void",
"onClick",
"(",
"final",
"ClickEvent",
"event",
")",
"{",
"keypos",
"=",
"pos",
";",
"}",
"}",
")",
";",
"rb",
".",
"addClickHandler",
"(",
"refreshgraph",
")",
";",
"grid",
".",
"setWidget",
"(",
"row",
",",
"col",
",",
"rb",
")",
";",
"keypos_map",
".",
"put",
"(",
"pos",
",",
"rb",
")",
";",
"return",
"rb",
";",
"}"
] |
Small helper to build a radio button used to change the position of the
key of the graph.
|
[
"Small",
"helper",
"to",
"build",
"a",
"radio",
"button",
"used",
"to",
"change",
"the",
"position",
"of",
"the",
"key",
"of",
"the",
"graph",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryUi.java#L556-L569
|
13,743
|
OpenTSDB/opentsdb
|
src/tsd/client/QueryUi.java
|
QueryUi.ensureSameWidgetSize
|
private static void ensureSameWidgetSize(final DecoratedTabPanel panel) {
if (!panel.isAttached()) {
throw new IllegalArgumentException("panel not attached: " + panel);
}
int maxw = 0;
int maxh = 0;
for (final Widget widget : panel) {
final int w = widget.getOffsetWidth();
final int h = widget.getOffsetHeight();
if (w > maxw) {
maxw = w;
}
if (h > maxh) {
maxh = h;
}
}
if (maxw == 0 || maxh == 0) {
throw new IllegalArgumentException("maxw=" + maxw + " maxh=" + maxh);
}
for (final Widget widget : panel) {
setOffsetWidth(widget, maxw);
setOffsetHeight(widget, maxh);
}
}
|
java
|
private static void ensureSameWidgetSize(final DecoratedTabPanel panel) {
if (!panel.isAttached()) {
throw new IllegalArgumentException("panel not attached: " + panel);
}
int maxw = 0;
int maxh = 0;
for (final Widget widget : panel) {
final int w = widget.getOffsetWidth();
final int h = widget.getOffsetHeight();
if (w > maxw) {
maxw = w;
}
if (h > maxh) {
maxh = h;
}
}
if (maxw == 0 || maxh == 0) {
throw new IllegalArgumentException("maxw=" + maxw + " maxh=" + maxh);
}
for (final Widget widget : panel) {
setOffsetWidth(widget, maxw);
setOffsetHeight(widget, maxh);
}
}
|
[
"private",
"static",
"void",
"ensureSameWidgetSize",
"(",
"final",
"DecoratedTabPanel",
"panel",
")",
"{",
"if",
"(",
"!",
"panel",
".",
"isAttached",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"panel not attached: \"",
"+",
"panel",
")",
";",
"}",
"int",
"maxw",
"=",
"0",
";",
"int",
"maxh",
"=",
"0",
";",
"for",
"(",
"final",
"Widget",
"widget",
":",
"panel",
")",
"{",
"final",
"int",
"w",
"=",
"widget",
".",
"getOffsetWidth",
"(",
")",
";",
"final",
"int",
"h",
"=",
"widget",
".",
"getOffsetHeight",
"(",
")",
";",
"if",
"(",
"w",
">",
"maxw",
")",
"{",
"maxw",
"=",
"w",
";",
"}",
"if",
"(",
"h",
">",
"maxh",
")",
"{",
"maxh",
"=",
"h",
";",
"}",
"}",
"if",
"(",
"maxw",
"==",
"0",
"||",
"maxh",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"maxw=\"",
"+",
"maxw",
"+",
"\" maxh=\"",
"+",
"maxh",
")",
";",
"}",
"for",
"(",
"final",
"Widget",
"widget",
":",
"panel",
")",
"{",
"setOffsetWidth",
"(",
"widget",
",",
"maxw",
")",
";",
"setOffsetHeight",
"(",
"widget",
",",
"maxh",
")",
";",
"}",
"}"
] |
Ensures all the widgets in the given panel have the same size.
Otherwise by default the panel will automatically resize itself to the
contents of the currently active panel's widget, which is annoying
because it makes a number of things move around in the UI.
@param panel The panel containing the widgets to resize.
|
[
"Ensures",
"all",
"the",
"widgets",
"in",
"the",
"given",
"panel",
"have",
"the",
"same",
"size",
".",
"Otherwise",
"by",
"default",
"the",
"panel",
"will",
"automatically",
"resize",
"itself",
"to",
"the",
"contents",
"of",
"the",
"currently",
"active",
"panel",
"s",
"widget",
"which",
"is",
"annoying",
"because",
"it",
"makes",
"a",
"number",
"of",
"things",
"move",
"around",
"in",
"the",
"UI",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryUi.java#L1384-L1407
|
13,744
|
OpenTSDB/opentsdb
|
src/tsd/client/QueryUi.java
|
QueryUi.setOffsetWidth
|
private static void setOffsetWidth(final Widget widget, int width) {
widget.setWidth(width + "px");
final int offset = widget.getOffsetWidth();
if (offset > 0) {
width -= offset - width;
if (width > 0) {
widget.setWidth(width + "px");
}
}
}
|
java
|
private static void setOffsetWidth(final Widget widget, int width) {
widget.setWidth(width + "px");
final int offset = widget.getOffsetWidth();
if (offset > 0) {
width -= offset - width;
if (width > 0) {
widget.setWidth(width + "px");
}
}
}
|
[
"private",
"static",
"void",
"setOffsetWidth",
"(",
"final",
"Widget",
"widget",
",",
"int",
"width",
")",
"{",
"widget",
".",
"setWidth",
"(",
"width",
"+",
"\"px\"",
")",
";",
"final",
"int",
"offset",
"=",
"widget",
".",
"getOffsetWidth",
"(",
")",
";",
"if",
"(",
"offset",
">",
"0",
")",
"{",
"width",
"-=",
"offset",
"-",
"width",
";",
"if",
"(",
"width",
">",
"0",
")",
"{",
"widget",
".",
"setWidth",
"(",
"width",
"+",
"\"px\"",
")",
";",
"}",
"}",
"}"
] |
Properly sets the total width of a widget.
This takes into account decorations such as border, margin, and padding.
|
[
"Properly",
"sets",
"the",
"total",
"width",
"of",
"a",
"widget",
".",
"This",
"takes",
"into",
"account",
"decorations",
"such",
"as",
"border",
"margin",
"and",
"padding",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryUi.java#L1413-L1422
|
13,745
|
OpenTSDB/opentsdb
|
src/tsd/client/QueryUi.java
|
QueryUi.setOffsetHeight
|
private static void setOffsetHeight(final Widget widget, int height) {
widget.setHeight(height + "px");
final int offset = widget.getOffsetHeight();
if (offset > 0) {
height -= offset - height;
if (height > 0) {
widget.setHeight(height + "px");
}
}
}
|
java
|
private static void setOffsetHeight(final Widget widget, int height) {
widget.setHeight(height + "px");
final int offset = widget.getOffsetHeight();
if (offset > 0) {
height -= offset - height;
if (height > 0) {
widget.setHeight(height + "px");
}
}
}
|
[
"private",
"static",
"void",
"setOffsetHeight",
"(",
"final",
"Widget",
"widget",
",",
"int",
"height",
")",
"{",
"widget",
".",
"setHeight",
"(",
"height",
"+",
"\"px\"",
")",
";",
"final",
"int",
"offset",
"=",
"widget",
".",
"getOffsetHeight",
"(",
")",
";",
"if",
"(",
"offset",
">",
"0",
")",
"{",
"height",
"-=",
"offset",
"-",
"height",
";",
"if",
"(",
"height",
">",
"0",
")",
"{",
"widget",
".",
"setHeight",
"(",
"height",
"+",
"\"px\"",
")",
";",
"}",
"}",
"}"
] |
Properly sets the total height of a widget.
This takes into account decorations such as border, margin, and padding.
|
[
"Properly",
"sets",
"the",
"total",
"height",
"of",
"a",
"widget",
".",
"This",
"takes",
"into",
"account",
"decorations",
"such",
"as",
"border",
"margin",
"and",
"padding",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/QueryUi.java#L1428-L1437
|
13,746
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.parse
|
public static void parse(final HashMap<String, String> tags,
final String tag) {
final String[] kv = splitString(tag, '=');
if (kv.length != 2 || kv[0].length() <= 0 || kv[1].length() <= 0) {
throw new IllegalArgumentException("invalid tag: " + tag);
}
if (kv[1].equals(tags.get(kv[0]))) {
return;
}
if (tags.get(kv[0]) != null) {
throw new IllegalArgumentException("duplicate tag: " + tag
+ ", tags=" + tags);
}
tags.put(kv[0], kv[1]);
}
|
java
|
public static void parse(final HashMap<String, String> tags,
final String tag) {
final String[] kv = splitString(tag, '=');
if (kv.length != 2 || kv[0].length() <= 0 || kv[1].length() <= 0) {
throw new IllegalArgumentException("invalid tag: " + tag);
}
if (kv[1].equals(tags.get(kv[0]))) {
return;
}
if (tags.get(kv[0]) != null) {
throw new IllegalArgumentException("duplicate tag: " + tag
+ ", tags=" + tags);
}
tags.put(kv[0], kv[1]);
}
|
[
"public",
"static",
"void",
"parse",
"(",
"final",
"HashMap",
"<",
"String",
",",
"String",
">",
"tags",
",",
"final",
"String",
"tag",
")",
"{",
"final",
"String",
"[",
"]",
"kv",
"=",
"splitString",
"(",
"tag",
",",
"'",
"'",
")",
";",
"if",
"(",
"kv",
".",
"length",
"!=",
"2",
"||",
"kv",
"[",
"0",
"]",
".",
"length",
"(",
")",
"<=",
"0",
"||",
"kv",
"[",
"1",
"]",
".",
"length",
"(",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid tag: \"",
"+",
"tag",
")",
";",
"}",
"if",
"(",
"kv",
"[",
"1",
"]",
".",
"equals",
"(",
"tags",
".",
"get",
"(",
"kv",
"[",
"0",
"]",
")",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"tags",
".",
"get",
"(",
"kv",
"[",
"0",
"]",
")",
"!=",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"duplicate tag: \"",
"+",
"tag",
"+",
"\", tags=\"",
"+",
"tags",
")",
";",
"}",
"tags",
".",
"put",
"(",
"kv",
"[",
"0",
"]",
",",
"kv",
"[",
"1",
"]",
")",
";",
"}"
] |
Parses a tag into a HashMap.
@param tags The HashMap into which to store the tag.
@param tag A String of the form "tag=value".
@throws IllegalArgumentException if the tag is malformed.
@throws IllegalArgumentException if the tag was already in tags with a
different value.
|
[
"Parses",
"a",
"tag",
"into",
"a",
"HashMap",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L87-L101
|
13,747
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.parseWithMetric
|
public static String parseWithMetric(final String metric,
final List<Pair<String, String>> tags) {
final int curly = metric.indexOf('{');
if (curly < 0) {
if (metric.isEmpty()) {
throw new IllegalArgumentException("Metric string was empty");
}
return metric;
}
final int len = metric.length();
if (metric.charAt(len - 1) != '}') { // "foo{"
throw new IllegalArgumentException("Missing '}' at the end of: " + metric);
} else if (curly == len - 2) { // "foo{}"
if (metric.charAt(0) == '{') {
throw new IllegalArgumentException("Missing metric and tags: " + metric);
}
return metric.substring(0, len - 2);
}
// substring the tags out of "foo{a=b,...,x=y}" and parse them.
for (final String tag : splitString(metric.substring(curly + 1, len - 1),
',')) {
try {
parse(tags, tag);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("When parsing tag '" + tag
+ "': " + e.getMessage());
}
}
// Return the "foo" part of "foo{a=b,...,x=y}"
if (metric.charAt(0) == '{') {
return null;
}
return metric.substring(0, curly);
}
|
java
|
public static String parseWithMetric(final String metric,
final List<Pair<String, String>> tags) {
final int curly = metric.indexOf('{');
if (curly < 0) {
if (metric.isEmpty()) {
throw new IllegalArgumentException("Metric string was empty");
}
return metric;
}
final int len = metric.length();
if (metric.charAt(len - 1) != '}') { // "foo{"
throw new IllegalArgumentException("Missing '}' at the end of: " + metric);
} else if (curly == len - 2) { // "foo{}"
if (metric.charAt(0) == '{') {
throw new IllegalArgumentException("Missing metric and tags: " + metric);
}
return metric.substring(0, len - 2);
}
// substring the tags out of "foo{a=b,...,x=y}" and parse them.
for (final String tag : splitString(metric.substring(curly + 1, len - 1),
',')) {
try {
parse(tags, tag);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("When parsing tag '" + tag
+ "': " + e.getMessage());
}
}
// Return the "foo" part of "foo{a=b,...,x=y}"
if (metric.charAt(0) == '{') {
return null;
}
return metric.substring(0, curly);
}
|
[
"public",
"static",
"String",
"parseWithMetric",
"(",
"final",
"String",
"metric",
",",
"final",
"List",
"<",
"Pair",
"<",
"String",
",",
"String",
">",
">",
"tags",
")",
"{",
"final",
"int",
"curly",
"=",
"metric",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"curly",
"<",
"0",
")",
"{",
"if",
"(",
"metric",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Metric string was empty\"",
")",
";",
"}",
"return",
"metric",
";",
"}",
"final",
"int",
"len",
"=",
"metric",
".",
"length",
"(",
")",
";",
"if",
"(",
"metric",
".",
"charAt",
"(",
"len",
"-",
"1",
")",
"!=",
"'",
"'",
")",
"{",
"// \"foo{\"",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Missing '}' at the end of: \"",
"+",
"metric",
")",
";",
"}",
"else",
"if",
"(",
"curly",
"==",
"len",
"-",
"2",
")",
"{",
"// \"foo{}\"",
"if",
"(",
"metric",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Missing metric and tags: \"",
"+",
"metric",
")",
";",
"}",
"return",
"metric",
".",
"substring",
"(",
"0",
",",
"len",
"-",
"2",
")",
";",
"}",
"// substring the tags out of \"foo{a=b,...,x=y}\" and parse them.",
"for",
"(",
"final",
"String",
"tag",
":",
"splitString",
"(",
"metric",
".",
"substring",
"(",
"curly",
"+",
"1",
",",
"len",
"-",
"1",
")",
",",
"'",
"'",
")",
")",
"{",
"try",
"{",
"parse",
"(",
"tags",
",",
"tag",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"When parsing tag '\"",
"+",
"tag",
"+",
"\"': \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"// Return the \"foo\" part of \"foo{a=b,...,x=y}\"",
"if",
"(",
"metric",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
")",
"{",
"return",
"null",
";",
"}",
"return",
"metric",
".",
"substring",
"(",
"0",
",",
"curly",
")",
";",
"}"
] |
Parses an optional metric and tags out of the given string, any of
which may be null. Requires at least one metric, tagk or tagv.
@param metric A string of the form "metric" or "metric{tag=value,...}"
or even "{tag=value,...}" where the metric may be missing.
@param tags The list to populate with parsed tag pairs
@return The name of the metric if it exists, null otherwise
@throws IllegalArgumentException if the metric is malformed.
@since 2.1
|
[
"Parses",
"an",
"optional",
"metric",
"and",
"tags",
"out",
"of",
"the",
"given",
"string",
"any",
"of",
"which",
"may",
"be",
"null",
".",
"Requires",
"at",
"least",
"one",
"metric",
"tagk",
"or",
"tagv",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L175-L208
|
13,748
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.getValue
|
static String getValue(final TSDB tsdb, final byte[] row,
final String name) throws NoSuchUniqueName {
validateString("tag name", name);
final byte[] id = tsdb.tag_names.getId(name);
final byte[] value_id = getValueId(tsdb, row, id);
if (value_id == null) {
return null;
}
// This shouldn't throw a NoSuchUniqueId.
try {
return tsdb.tag_values.getName(value_id);
} catch (NoSuchUniqueId e) {
LOG.error("Internal error, NoSuchUniqueId unexpected here!", e);
throw e;
}
}
|
java
|
static String getValue(final TSDB tsdb, final byte[] row,
final String name) throws NoSuchUniqueName {
validateString("tag name", name);
final byte[] id = tsdb.tag_names.getId(name);
final byte[] value_id = getValueId(tsdb, row, id);
if (value_id == null) {
return null;
}
// This shouldn't throw a NoSuchUniqueId.
try {
return tsdb.tag_values.getName(value_id);
} catch (NoSuchUniqueId e) {
LOG.error("Internal error, NoSuchUniqueId unexpected here!", e);
throw e;
}
}
|
[
"static",
"String",
"getValue",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"byte",
"[",
"]",
"row",
",",
"final",
"String",
"name",
")",
"throws",
"NoSuchUniqueName",
"{",
"validateString",
"(",
"\"tag name\"",
",",
"name",
")",
";",
"final",
"byte",
"[",
"]",
"id",
"=",
"tsdb",
".",
"tag_names",
".",
"getId",
"(",
"name",
")",
";",
"final",
"byte",
"[",
"]",
"value_id",
"=",
"getValueId",
"(",
"tsdb",
",",
"row",
",",
"id",
")",
";",
"if",
"(",
"value_id",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"// This shouldn't throw a NoSuchUniqueId.",
"try",
"{",
"return",
"tsdb",
".",
"tag_values",
".",
"getName",
"(",
"value_id",
")",
";",
"}",
"catch",
"(",
"NoSuchUniqueId",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Internal error, NoSuchUniqueId unexpected here!\"",
",",
"e",
")",
";",
"throw",
"e",
";",
"}",
"}"
] |
Extracts the value of the given tag name from the given row key.
@param tsdb The TSDB instance to use for UniqueId lookups.
@param row The row key in which to search the tag name.
@param name The name of the tag to search in the row key.
@return The value associated with the given tag name, or null if this tag
isn't present in this row key.
|
[
"Extracts",
"the",
"value",
"of",
"the",
"given",
"tag",
"name",
"from",
"the",
"given",
"row",
"key",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L337-L352
|
13,749
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.getValueId
|
static byte[] getValueId(final TSDB tsdb, final byte[] row,
final byte[] tag_id) {
final short name_width = tsdb.tag_names.width();
final short value_width = tsdb.tag_values.width();
// TODO(tsuna): Can do a binary search.
for (short pos = (short) (Const.SALT_WIDTH() +
tsdb.metrics.width() + Const.TIMESTAMP_BYTES);
pos < row.length;
pos += name_width + value_width) {
if (rowContains(row, pos, tag_id)) {
pos += name_width;
return Arrays.copyOfRange(row, pos, pos + value_width);
}
}
return null;
}
|
java
|
static byte[] getValueId(final TSDB tsdb, final byte[] row,
final byte[] tag_id) {
final short name_width = tsdb.tag_names.width();
final short value_width = tsdb.tag_values.width();
// TODO(tsuna): Can do a binary search.
for (short pos = (short) (Const.SALT_WIDTH() +
tsdb.metrics.width() + Const.TIMESTAMP_BYTES);
pos < row.length;
pos += name_width + value_width) {
if (rowContains(row, pos, tag_id)) {
pos += name_width;
return Arrays.copyOfRange(row, pos, pos + value_width);
}
}
return null;
}
|
[
"static",
"byte",
"[",
"]",
"getValueId",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"byte",
"[",
"]",
"row",
",",
"final",
"byte",
"[",
"]",
"tag_id",
")",
"{",
"final",
"short",
"name_width",
"=",
"tsdb",
".",
"tag_names",
".",
"width",
"(",
")",
";",
"final",
"short",
"value_width",
"=",
"tsdb",
".",
"tag_values",
".",
"width",
"(",
")",
";",
"// TODO(tsuna): Can do a binary search.",
"for",
"(",
"short",
"pos",
"=",
"(",
"short",
")",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"tsdb",
".",
"metrics",
".",
"width",
"(",
")",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
")",
";",
"pos",
"<",
"row",
".",
"length",
";",
"pos",
"+=",
"name_width",
"+",
"value_width",
")",
"{",
"if",
"(",
"rowContains",
"(",
"row",
",",
"pos",
",",
"tag_id",
")",
")",
"{",
"pos",
"+=",
"name_width",
";",
"return",
"Arrays",
".",
"copyOfRange",
"(",
"row",
",",
"pos",
",",
"pos",
"+",
"value_width",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Extracts the value ID of the given tag UD name from the given row key.
@param tsdb The TSDB instance to use for UniqueId lookups.
@param row The row key in which to search the tag name.
@param tag_id The name of the tag to search in the row key.
@return The value ID associated with the given tag ID, or null if this
tag ID isn't present in this row key.
|
[
"Extracts",
"the",
"value",
"ID",
"of",
"the",
"given",
"tag",
"UD",
"name",
"from",
"the",
"given",
"row",
"key",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L362-L377
|
13,750
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.rowContains
|
private static boolean rowContains(final byte[] row,
short offset, final byte[] bytes) {
for (int pos = bytes.length - 1; pos >= 0; pos--) {
if (row[offset + pos] != bytes[pos]) {
return false;
}
}
return true;
}
|
java
|
private static boolean rowContains(final byte[] row,
short offset, final byte[] bytes) {
for (int pos = bytes.length - 1; pos >= 0; pos--) {
if (row[offset + pos] != bytes[pos]) {
return false;
}
}
return true;
}
|
[
"private",
"static",
"boolean",
"rowContains",
"(",
"final",
"byte",
"[",
"]",
"row",
",",
"short",
"offset",
",",
"final",
"byte",
"[",
"]",
"bytes",
")",
"{",
"for",
"(",
"int",
"pos",
"=",
"bytes",
".",
"length",
"-",
"1",
";",
"pos",
">=",
"0",
";",
"pos",
"--",
")",
"{",
"if",
"(",
"row",
"[",
"offset",
"+",
"pos",
"]",
"!=",
"bytes",
"[",
"pos",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Checks whether or not the row key contains the given byte array at the
given offset.
@param row The row key in which to search.
@param offset The offset in {@code row} at which to start searching.
@param bytes The bytes to search that the given offset.
@return true if {@code bytes} are present in {@code row} at
{@code offset}, false otherwise.
|
[
"Checks",
"whether",
"or",
"not",
"the",
"row",
"key",
"contains",
"the",
"given",
"byte",
"array",
"at",
"the",
"given",
"offset",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L388-L396
|
13,751
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.getTagUids
|
public static ByteMap<byte[]> getTagUids(final byte[] row) {
final ByteMap<byte[]> uids = new ByteMap<byte[]>();
final short name_width = TSDB.tagk_width();
final short value_width = TSDB.tagv_width();
final short tag_bytes = (short) (name_width + value_width);
final short metric_ts_bytes = (short) (TSDB.metrics_width()
+ Const.TIMESTAMP_BYTES
+ Const.SALT_WIDTH());
for (short pos = metric_ts_bytes; pos < row.length; pos += tag_bytes) {
final byte[] tmp_name = new byte[name_width];
final byte[] tmp_value = new byte[value_width];
System.arraycopy(row, pos, tmp_name, 0, name_width);
System.arraycopy(row, pos + name_width, tmp_value, 0, value_width);
uids.put(tmp_name, tmp_value);
}
return uids;
}
|
java
|
public static ByteMap<byte[]> getTagUids(final byte[] row) {
final ByteMap<byte[]> uids = new ByteMap<byte[]>();
final short name_width = TSDB.tagk_width();
final short value_width = TSDB.tagv_width();
final short tag_bytes = (short) (name_width + value_width);
final short metric_ts_bytes = (short) (TSDB.metrics_width()
+ Const.TIMESTAMP_BYTES
+ Const.SALT_WIDTH());
for (short pos = metric_ts_bytes; pos < row.length; pos += tag_bytes) {
final byte[] tmp_name = new byte[name_width];
final byte[] tmp_value = new byte[value_width];
System.arraycopy(row, pos, tmp_name, 0, name_width);
System.arraycopy(row, pos + name_width, tmp_value, 0, value_width);
uids.put(tmp_name, tmp_value);
}
return uids;
}
|
[
"public",
"static",
"ByteMap",
"<",
"byte",
"[",
"]",
">",
"getTagUids",
"(",
"final",
"byte",
"[",
"]",
"row",
")",
"{",
"final",
"ByteMap",
"<",
"byte",
"[",
"]",
">",
"uids",
"=",
"new",
"ByteMap",
"<",
"byte",
"[",
"]",
">",
"(",
")",
";",
"final",
"short",
"name_width",
"=",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"final",
"short",
"value_width",
"=",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"final",
"short",
"tag_bytes",
"=",
"(",
"short",
")",
"(",
"name_width",
"+",
"value_width",
")",
";",
"final",
"short",
"metric_ts_bytes",
"=",
"(",
"short",
")",
"(",
"TSDB",
".",
"metrics_width",
"(",
")",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
"+",
"Const",
".",
"SALT_WIDTH",
"(",
")",
")",
";",
"for",
"(",
"short",
"pos",
"=",
"metric_ts_bytes",
";",
"pos",
"<",
"row",
".",
"length",
";",
"pos",
"+=",
"tag_bytes",
")",
"{",
"final",
"byte",
"[",
"]",
"tmp_name",
"=",
"new",
"byte",
"[",
"name_width",
"]",
";",
"final",
"byte",
"[",
"]",
"tmp_value",
"=",
"new",
"byte",
"[",
"value_width",
"]",
";",
"System",
".",
"arraycopy",
"(",
"row",
",",
"pos",
",",
"tmp_name",
",",
"0",
",",
"name_width",
")",
";",
"System",
".",
"arraycopy",
"(",
"row",
",",
"pos",
"+",
"name_width",
",",
"tmp_value",
",",
"0",
",",
"value_width",
")",
";",
"uids",
".",
"put",
"(",
"tmp_name",
",",
"tmp_value",
")",
";",
"}",
"return",
"uids",
";",
"}"
] |
Returns the tag key and value pairs as a byte map given a row key
@param row The row key to parse the UIDs from
@return A byte map with tagk and tagv pairs as raw UIDs
@since 2.2
|
[
"Returns",
"the",
"tag",
"key",
"and",
"value",
"pairs",
"as",
"a",
"byte",
"map",
"given",
"a",
"row",
"key"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L524-L541
|
13,752
|
OpenTSDB/opentsdb
|
src/core/Tags.java
|
Tags.resolveAllAsync
|
public static Deferred<ArrayList<byte[]>> resolveAllAsync(final TSDB tsdb,
final Map<String, String> tags) {
return resolveAllInternalAsync(tsdb, null, tags, false);
}
|
java
|
public static Deferred<ArrayList<byte[]>> resolveAllAsync(final TSDB tsdb,
final Map<String, String> tags) {
return resolveAllInternalAsync(tsdb, null, tags, false);
}
|
[
"public",
"static",
"Deferred",
"<",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
">",
"resolveAllAsync",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"tags",
")",
"{",
"return",
"resolveAllInternalAsync",
"(",
"tsdb",
",",
"null",
",",
"tags",
",",
"false",
")",
";",
"}"
] |
Resolves a set of tag strings to their UIDs asynchronously
@param tsdb the TSDB to use for access
@param tags The tags to resolve
@return A deferred with the list of UIDs in tagk1, tagv1, .. tagkn, tagvn
order
@throws NoSuchUniqueName if one of the elements in the map contained an
unknown tag name or tag value.
@since 2.1
|
[
"Resolves",
"a",
"set",
"of",
"tag",
"strings",
"to",
"their",
"UIDs",
"asynchronously"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Tags.java#L598-L601
|
13,753
|
OpenTSDB/opentsdb
|
src/core/ColumnDatapointIterator.java
|
ColumnDatapointIterator.writeToBuffers
|
public void writeToBuffers(ByteBufferList compQualifier, ByteBufferList compValue) {
compQualifier.add(qualifier, qualifier_offset, current_qual_length);
compValue.add(value, value_offset, current_val_length);
}
|
java
|
public void writeToBuffers(ByteBufferList compQualifier, ByteBufferList compValue) {
compQualifier.add(qualifier, qualifier_offset, current_qual_length);
compValue.add(value, value_offset, current_val_length);
}
|
[
"public",
"void",
"writeToBuffers",
"(",
"ByteBufferList",
"compQualifier",
",",
"ByteBufferList",
"compValue",
")",
"{",
"compQualifier",
".",
"add",
"(",
"qualifier",
",",
"qualifier_offset",
",",
"current_qual_length",
")",
";",
"compValue",
".",
"add",
"(",
"value",
",",
"value_offset",
",",
"current_val_length",
")",
";",
"}"
] |
Copy this value to the output and advance to the next one.
@param compQualifier
@param compValue
@return true if there is more data left in this column
|
[
"Copy",
"this",
"value",
"to",
"the",
"output",
"and",
"advance",
"to",
"the",
"next",
"one",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/ColumnDatapointIterator.java#L118-L121
|
13,754
|
OpenTSDB/opentsdb
|
src/core/ColumnDatapointIterator.java
|
ColumnDatapointIterator.compareTo
|
@Override
public int compareTo(ColumnDatapointIterator o) {
int c = current_timestamp_offset - o.current_timestamp_offset;
if (c == 0) {
// note inverse order of comparison!
c = Long.signum(o.column_timestamp - column_timestamp);
}
return c;
}
|
java
|
@Override
public int compareTo(ColumnDatapointIterator o) {
int c = current_timestamp_offset - o.current_timestamp_offset;
if (c == 0) {
// note inverse order of comparison!
c = Long.signum(o.column_timestamp - column_timestamp);
}
return c;
}
|
[
"@",
"Override",
"public",
"int",
"compareTo",
"(",
"ColumnDatapointIterator",
"o",
")",
"{",
"int",
"c",
"=",
"current_timestamp_offset",
"-",
"o",
".",
"current_timestamp_offset",
";",
"if",
"(",
"c",
"==",
"0",
")",
"{",
"// note inverse order of comparison!",
"c",
"=",
"Long",
".",
"signum",
"(",
"o",
".",
"column_timestamp",
"-",
"column_timestamp",
")",
";",
"}",
"return",
"c",
";",
"}"
] |
entry we are going to keep first, and don't have to copy over it)
|
[
"entry",
"we",
"are",
"going",
"to",
"keep",
"first",
"and",
"don",
"t",
"have",
"to",
"copy",
"over",
"it",
")"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/ColumnDatapointIterator.java#L191-L199
|
13,755
|
OpenTSDB/opentsdb
|
src/query/expression/ExpressionTree.java
|
ExpressionTree.addSubMetricQuery
|
public void addSubMetricQuery(final String metric_query,
final int sub_query_index,
final int param_index) {
if (metric_query == null || metric_query.isEmpty()) {
throw new IllegalArgumentException("Metric query cannot be null or empty");
}
if (sub_query_index < 0) {
throw new IllegalArgumentException("Sub query index must be 0 or greater");
}
if (param_index < 0) {
throw new IllegalArgumentException("Parameter index must be 0 or greater");
}
if (sub_metric_queries == null) {
sub_metric_queries = Maps.newHashMap();
}
sub_metric_queries.put(sub_query_index, metric_query);
parameter_index.put(param_index, Parameter.METRIC_QUERY);
}
|
java
|
public void addSubMetricQuery(final String metric_query,
final int sub_query_index,
final int param_index) {
if (metric_query == null || metric_query.isEmpty()) {
throw new IllegalArgumentException("Metric query cannot be null or empty");
}
if (sub_query_index < 0) {
throw new IllegalArgumentException("Sub query index must be 0 or greater");
}
if (param_index < 0) {
throw new IllegalArgumentException("Parameter index must be 0 or greater");
}
if (sub_metric_queries == null) {
sub_metric_queries = Maps.newHashMap();
}
sub_metric_queries.put(sub_query_index, metric_query);
parameter_index.put(param_index, Parameter.METRIC_QUERY);
}
|
[
"public",
"void",
"addSubMetricQuery",
"(",
"final",
"String",
"metric_query",
",",
"final",
"int",
"sub_query_index",
",",
"final",
"int",
"param_index",
")",
"{",
"if",
"(",
"metric_query",
"==",
"null",
"||",
"metric_query",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Metric query cannot be null or empty\"",
")",
";",
"}",
"if",
"(",
"sub_query_index",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Sub query index must be 0 or greater\"",
")",
";",
"}",
"if",
"(",
"param_index",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Parameter index must be 0 or greater\"",
")",
";",
"}",
"if",
"(",
"sub_metric_queries",
"==",
"null",
")",
"{",
"sub_metric_queries",
"=",
"Maps",
".",
"newHashMap",
"(",
")",
";",
"}",
"sub_metric_queries",
".",
"put",
"(",
"sub_query_index",
",",
"metric_query",
")",
";",
"parameter_index",
".",
"put",
"(",
"param_index",
",",
"Parameter",
".",
"METRIC_QUERY",
")",
";",
"}"
] |
Sets the metric query key and index, setting the Parameter type to
METRIC_QUERY
@param metric_query The metric query id
@param sub_query_index The index of the metric query
@param param_index The index of the parameter (??)
|
[
"Sets",
"the",
"metric",
"query",
"key",
"and",
"index",
"setting",
"the",
"Parameter",
"type",
"to",
"METRIC_QUERY"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/ExpressionTree.java#L109-L126
|
13,756
|
OpenTSDB/opentsdb
|
src/query/expression/ExpressionTree.java
|
ExpressionTree.addFunctionParameter
|
public void addFunctionParameter(final String param) {
if (param == null || param.isEmpty()) {
throw new IllegalArgumentException("Parameter cannot be null or empty");
}
if (func_params == null) {
func_params = Lists.newArrayList();
}
func_params.add(param);
}
|
java
|
public void addFunctionParameter(final String param) {
if (param == null || param.isEmpty()) {
throw new IllegalArgumentException("Parameter cannot be null or empty");
}
if (func_params == null) {
func_params = Lists.newArrayList();
}
func_params.add(param);
}
|
[
"public",
"void",
"addFunctionParameter",
"(",
"final",
"String",
"param",
")",
"{",
"if",
"(",
"param",
"==",
"null",
"||",
"param",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Parameter cannot be null or empty\"",
")",
";",
"}",
"if",
"(",
"func_params",
"==",
"null",
")",
"{",
"func_params",
"=",
"Lists",
".",
"newArrayList",
"(",
")",
";",
"}",
"func_params",
".",
"add",
"(",
"param",
")",
";",
"}"
] |
Adds parameters for the root expression only.
@param param The parameter to add, cannot be null or empty
@throws IllegalArgumentException if the parameter is null or empty
|
[
"Adds",
"parameters",
"for",
"the",
"root",
"expression",
"only",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/ExpressionTree.java#L133-L141
|
13,757
|
OpenTSDB/opentsdb
|
src/query/expression/ExpressionTree.java
|
ExpressionTree.clean
|
private String clean(final Collection<String> values) {
if (values == null || values.size() == 0) {
return "";
}
final List<String> strs = Lists.newArrayList();
for (String v : values) {
final String tmp = v.replaceAll("\\{.*\\}", "");
final int ix = tmp.lastIndexOf(':');
if (ix < 0) {
strs.add(tmp);
} else {
strs.add(tmp.substring(ix+1));
}
}
return DOUBLE_COMMA_JOINER.join(strs);
}
|
java
|
private String clean(final Collection<String> values) {
if (values == null || values.size() == 0) {
return "";
}
final List<String> strs = Lists.newArrayList();
for (String v : values) {
final String tmp = v.replaceAll("\\{.*\\}", "");
final int ix = tmp.lastIndexOf(':');
if (ix < 0) {
strs.add(tmp);
} else {
strs.add(tmp.substring(ix+1));
}
}
return DOUBLE_COMMA_JOINER.join(strs);
}
|
[
"private",
"String",
"clean",
"(",
"final",
"Collection",
"<",
"String",
">",
"values",
")",
"{",
"if",
"(",
"values",
"==",
"null",
"||",
"values",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"return",
"\"\"",
";",
"}",
"final",
"List",
"<",
"String",
">",
"strs",
"=",
"Lists",
".",
"newArrayList",
"(",
")",
";",
"for",
"(",
"String",
"v",
":",
"values",
")",
"{",
"final",
"String",
"tmp",
"=",
"v",
".",
"replaceAll",
"(",
"\"\\\\{.*\\\\}\"",
",",
"\"\"",
")",
";",
"final",
"int",
"ix",
"=",
"tmp",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"ix",
"<",
"0",
")",
"{",
"strs",
".",
"add",
"(",
"tmp",
")",
";",
"}",
"else",
"{",
"strs",
".",
"add",
"(",
"tmp",
".",
"substring",
"(",
"ix",
"+",
"1",
")",
")",
";",
"}",
"}",
"return",
"DOUBLE_COMMA_JOINER",
".",
"join",
"(",
"strs",
")",
";",
"}"
] |
Helper to clean out some characters
@param values The collection of strings to cleanup
@return An empty string if values was empty or a cleaned up string
|
[
"Helper",
"to",
"clean",
"out",
"some",
"characters"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/ExpressionTree.java#L219-L236
|
13,758
|
OpenTSDB/opentsdb
|
src/tsd/client/EventsHandler.java
|
EventsHandler.scheduleEvent
|
private <H extends EventHandler> void scheduleEvent(final DomEvent<H> event) {
DeferredCommand.addCommand(new Command() {
public void execute() {
onEvent(event);
}
});
}
|
java
|
private <H extends EventHandler> void scheduleEvent(final DomEvent<H> event) {
DeferredCommand.addCommand(new Command() {
public void execute() {
onEvent(event);
}
});
}
|
[
"private",
"<",
"H",
"extends",
"EventHandler",
">",
"void",
"scheduleEvent",
"(",
"final",
"DomEvent",
"<",
"H",
">",
"event",
")",
"{",
"DeferredCommand",
".",
"addCommand",
"(",
"new",
"Command",
"(",
")",
"{",
"public",
"void",
"execute",
"(",
")",
"{",
"onEvent",
"(",
"event",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Executes the event using a deferred command.
|
[
"Executes",
"the",
"event",
"using",
"a",
"deferred",
"command",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/client/EventsHandler.java#L73-L79
|
13,759
|
perwendel/spark
|
src/main/java/spark/TemplateEngine.java
|
TemplateEngine.render
|
public String render(Object object) {
ModelAndView modelAndView = (ModelAndView) object;
return render(modelAndView);
}
|
java
|
public String render(Object object) {
ModelAndView modelAndView = (ModelAndView) object;
return render(modelAndView);
}
|
[
"public",
"String",
"render",
"(",
"Object",
"object",
")",
"{",
"ModelAndView",
"modelAndView",
"=",
"(",
"ModelAndView",
")",
"object",
";",
"return",
"render",
"(",
"modelAndView",
")",
";",
"}"
] |
Renders the object
@param object the object
@return the rendered model and view
|
[
"Renders",
"the",
"object"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/TemplateEngine.java#L19-L22
|
13,760
|
perwendel/spark
|
src/main/java/spark/resource/AbstractResourceHandler.java
|
AbstractResourceHandler.getResource
|
public AbstractFileResolvingResource getResource(HttpServletRequest request) throws MalformedURLException {
String servletPath;
String pathInfo;
boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
if (included) {
servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (servletPath == null && pathInfo == null) {
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
} else {
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
String pathInContext = addPaths(servletPath, pathInfo);
return getResource(pathInContext);
}
|
java
|
public AbstractFileResolvingResource getResource(HttpServletRequest request) throws MalformedURLException {
String servletPath;
String pathInfo;
boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
if (included) {
servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (servletPath == null && pathInfo == null) {
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
} else {
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
String pathInContext = addPaths(servletPath, pathInfo);
return getResource(pathInContext);
}
|
[
"public",
"AbstractFileResolvingResource",
"getResource",
"(",
"HttpServletRequest",
"request",
")",
"throws",
"MalformedURLException",
"{",
"String",
"servletPath",
";",
"String",
"pathInfo",
";",
"boolean",
"included",
"=",
"request",
".",
"getAttribute",
"(",
"RequestDispatcher",
".",
"INCLUDE_REQUEST_URI",
")",
"!=",
"null",
";",
"if",
"(",
"included",
")",
"{",
"servletPath",
"=",
"(",
"String",
")",
"request",
".",
"getAttribute",
"(",
"RequestDispatcher",
".",
"INCLUDE_SERVLET_PATH",
")",
";",
"pathInfo",
"=",
"(",
"String",
")",
"request",
".",
"getAttribute",
"(",
"RequestDispatcher",
".",
"INCLUDE_PATH_INFO",
")",
";",
"if",
"(",
"servletPath",
"==",
"null",
"&&",
"pathInfo",
"==",
"null",
")",
"{",
"servletPath",
"=",
"request",
".",
"getServletPath",
"(",
")",
";",
"pathInfo",
"=",
"request",
".",
"getPathInfo",
"(",
")",
";",
"}",
"}",
"else",
"{",
"servletPath",
"=",
"request",
".",
"getServletPath",
"(",
")",
";",
"pathInfo",
"=",
"request",
".",
"getPathInfo",
"(",
")",
";",
"}",
"String",
"pathInContext",
"=",
"addPaths",
"(",
"servletPath",
",",
"pathInfo",
")",
";",
"return",
"getResource",
"(",
"pathInContext",
")",
";",
"}"
] |
Gets a resource from a servlet request
@param request the servlet request
@return the resource or null if not found
@throws java.net.MalformedURLException thrown when malformed URL.
|
[
"Gets",
"a",
"resource",
"from",
"a",
"servlet",
"request"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/resource/AbstractResourceHandler.java#L40-L60
|
13,761
|
perwendel/spark
|
src/main/java/spark/embeddedserver/jetty/JettyServer.java
|
JettyServer.create
|
public Server create(int maxThreads, int minThreads, int threadTimeoutMillis) {
Server server;
if (maxThreads > 0) {
int max = maxThreads;
int min = (minThreads > 0) ? minThreads : 8;
int idleTimeout = (threadTimeoutMillis > 0) ? threadTimeoutMillis : 60000;
server = new Server(new QueuedThreadPool(max, min, idleTimeout));
} else {
server = new Server();
}
return server;
}
|
java
|
public Server create(int maxThreads, int minThreads, int threadTimeoutMillis) {
Server server;
if (maxThreads > 0) {
int max = maxThreads;
int min = (minThreads > 0) ? minThreads : 8;
int idleTimeout = (threadTimeoutMillis > 0) ? threadTimeoutMillis : 60000;
server = new Server(new QueuedThreadPool(max, min, idleTimeout));
} else {
server = new Server();
}
return server;
}
|
[
"public",
"Server",
"create",
"(",
"int",
"maxThreads",
",",
"int",
"minThreads",
",",
"int",
"threadTimeoutMillis",
")",
"{",
"Server",
"server",
";",
"if",
"(",
"maxThreads",
">",
"0",
")",
"{",
"int",
"max",
"=",
"maxThreads",
";",
"int",
"min",
"=",
"(",
"minThreads",
">",
"0",
")",
"?",
"minThreads",
":",
"8",
";",
"int",
"idleTimeout",
"=",
"(",
"threadTimeoutMillis",
">",
"0",
")",
"?",
"threadTimeoutMillis",
":",
"60000",
";",
"server",
"=",
"new",
"Server",
"(",
"new",
"QueuedThreadPool",
"(",
"max",
",",
"min",
",",
"idleTimeout",
")",
")",
";",
"}",
"else",
"{",
"server",
"=",
"new",
"Server",
"(",
")",
";",
"}",
"return",
"server",
";",
"}"
] |
Creates a Jetty server.
@param maxThreads maxThreads
@param minThreads minThreads
@param threadTimeoutMillis threadTimeoutMillis
@return a new jetty server instance
|
[
"Creates",
"a",
"Jetty",
"server",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/embeddedserver/jetty/JettyServer.java#L36-L50
|
13,762
|
perwendel/spark
|
src/main/java/spark/embeddedserver/jetty/JettyServer.java
|
JettyServer.create
|
@Override
public Server create(ThreadPool threadPool) {
return threadPool != null ? new Server(threadPool) : new Server();
}
|
java
|
@Override
public Server create(ThreadPool threadPool) {
return threadPool != null ? new Server(threadPool) : new Server();
}
|
[
"@",
"Override",
"public",
"Server",
"create",
"(",
"ThreadPool",
"threadPool",
")",
"{",
"return",
"threadPool",
"!=",
"null",
"?",
"new",
"Server",
"(",
"threadPool",
")",
":",
"new",
"Server",
"(",
")",
";",
"}"
] |
Creates a Jetty server with supplied thread pool
@param threadPool thread pool
@return a new jetty server instance
|
[
"Creates",
"a",
"Jetty",
"server",
"with",
"supplied",
"thread",
"pool"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/embeddedserver/jetty/JettyServer.java#L57-L60
|
13,763
|
perwendel/spark
|
src/main/java/spark/ExceptionMapper.java
|
ExceptionMapper.map
|
public void map(Class<? extends Exception> exceptionClass, ExceptionHandlerImpl handler) {
this.exceptionMap.put(exceptionClass, handler);
}
|
java
|
public void map(Class<? extends Exception> exceptionClass, ExceptionHandlerImpl handler) {
this.exceptionMap.put(exceptionClass, handler);
}
|
[
"public",
"void",
"map",
"(",
"Class",
"<",
"?",
"extends",
"Exception",
">",
"exceptionClass",
",",
"ExceptionHandlerImpl",
"handler",
")",
"{",
"this",
".",
"exceptionMap",
".",
"put",
"(",
"exceptionClass",
",",
"handler",
")",
";",
"}"
] |
Maps the given handler to the provided exception type. If a handler was already registered to the same type, the
handler is overwritten.
@param exceptionClass Type of exception
@param handler Handler to map to exception
|
[
"Maps",
"the",
"given",
"handler",
"to",
"the",
"provided",
"exception",
"type",
".",
"If",
"a",
"handler",
"was",
"already",
"registered",
"to",
"the",
"same",
"type",
"the",
"handler",
"is",
"overwritten",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/ExceptionMapper.java#L65-L67
|
13,764
|
perwendel/spark
|
src/main/java/spark/ExceptionMapper.java
|
ExceptionMapper.getHandler
|
public ExceptionHandlerImpl getHandler(Class<? extends Exception> exceptionClass) {
// If the exception map does not contain the provided exception class, it might
// still be that a superclass of the exception class is.
if (!this.exceptionMap.containsKey(exceptionClass)) {
Class<?> superclass = exceptionClass.getSuperclass();
do {
// Is the superclass mapped?
if (this.exceptionMap.containsKey(superclass)) {
// Use the handler for the mapped superclass, and cache handler
// for this exception class
ExceptionHandlerImpl handler = this.exceptionMap.get(superclass);
this.exceptionMap.put(exceptionClass, handler);
return handler;
}
// Iteratively walk through the exception class's superclasses
superclass = superclass.getSuperclass();
} while (superclass != null);
// No handler found either for the superclasses of the exception class
// We cache the null value to prevent future
this.exceptionMap.put(exceptionClass, null);
return null;
}
// Direct map
return this.exceptionMap.get(exceptionClass);
}
|
java
|
public ExceptionHandlerImpl getHandler(Class<? extends Exception> exceptionClass) {
// If the exception map does not contain the provided exception class, it might
// still be that a superclass of the exception class is.
if (!this.exceptionMap.containsKey(exceptionClass)) {
Class<?> superclass = exceptionClass.getSuperclass();
do {
// Is the superclass mapped?
if (this.exceptionMap.containsKey(superclass)) {
// Use the handler for the mapped superclass, and cache handler
// for this exception class
ExceptionHandlerImpl handler = this.exceptionMap.get(superclass);
this.exceptionMap.put(exceptionClass, handler);
return handler;
}
// Iteratively walk through the exception class's superclasses
superclass = superclass.getSuperclass();
} while (superclass != null);
// No handler found either for the superclasses of the exception class
// We cache the null value to prevent future
this.exceptionMap.put(exceptionClass, null);
return null;
}
// Direct map
return this.exceptionMap.get(exceptionClass);
}
|
[
"public",
"ExceptionHandlerImpl",
"getHandler",
"(",
"Class",
"<",
"?",
"extends",
"Exception",
">",
"exceptionClass",
")",
"{",
"// If the exception map does not contain the provided exception class, it might",
"// still be that a superclass of the exception class is.",
"if",
"(",
"!",
"this",
".",
"exceptionMap",
".",
"containsKey",
"(",
"exceptionClass",
")",
")",
"{",
"Class",
"<",
"?",
">",
"superclass",
"=",
"exceptionClass",
".",
"getSuperclass",
"(",
")",
";",
"do",
"{",
"// Is the superclass mapped?",
"if",
"(",
"this",
".",
"exceptionMap",
".",
"containsKey",
"(",
"superclass",
")",
")",
"{",
"// Use the handler for the mapped superclass, and cache handler",
"// for this exception class",
"ExceptionHandlerImpl",
"handler",
"=",
"this",
".",
"exceptionMap",
".",
"get",
"(",
"superclass",
")",
";",
"this",
".",
"exceptionMap",
".",
"put",
"(",
"exceptionClass",
",",
"handler",
")",
";",
"return",
"handler",
";",
"}",
"// Iteratively walk through the exception class's superclasses",
"superclass",
"=",
"superclass",
".",
"getSuperclass",
"(",
")",
";",
"}",
"while",
"(",
"superclass",
"!=",
"null",
")",
";",
"// No handler found either for the superclasses of the exception class",
"// We cache the null value to prevent future",
"this",
".",
"exceptionMap",
".",
"put",
"(",
"exceptionClass",
",",
"null",
")",
";",
"return",
"null",
";",
"}",
"// Direct map",
"return",
"this",
".",
"exceptionMap",
".",
"get",
"(",
"exceptionClass",
")",
";",
"}"
] |
Returns the handler associated with the provided exception class
@param exceptionClass Type of exception
@return Associated handler
|
[
"Returns",
"the",
"handler",
"associated",
"with",
"the",
"provided",
"exception",
"class"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/ExceptionMapper.java#L75-L103
|
13,765
|
perwendel/spark
|
src/main/java/spark/CustomErrorPages.java
|
CustomErrorPages.getFor
|
public static Object getFor(int status, Request request, Response response) {
Object customRenderer = CustomErrorPages.getInstance().customPages.get(status);
Object customPage = CustomErrorPages.getInstance().getDefaultFor(status);
if (customRenderer instanceof String) {
customPage = customRenderer;
} else if (customRenderer instanceof Route) {
try {
customPage = ((Route) customRenderer).handle(request, response);
} catch (Exception e) {
// The custom page renderer is causing an internal server error. Log exception as a warning and use default page instead
LOG.warn("Custom error page handler for status code {} has thrown an exception: {}. Using default page instead.", status, e.getMessage());
}
}
return customPage;
}
|
java
|
public static Object getFor(int status, Request request, Response response) {
Object customRenderer = CustomErrorPages.getInstance().customPages.get(status);
Object customPage = CustomErrorPages.getInstance().getDefaultFor(status);
if (customRenderer instanceof String) {
customPage = customRenderer;
} else if (customRenderer instanceof Route) {
try {
customPage = ((Route) customRenderer).handle(request, response);
} catch (Exception e) {
// The custom page renderer is causing an internal server error. Log exception as a warning and use default page instead
LOG.warn("Custom error page handler for status code {} has thrown an exception: {}. Using default page instead.", status, e.getMessage());
}
}
return customPage;
}
|
[
"public",
"static",
"Object",
"getFor",
"(",
"int",
"status",
",",
"Request",
"request",
",",
"Response",
"response",
")",
"{",
"Object",
"customRenderer",
"=",
"CustomErrorPages",
".",
"getInstance",
"(",
")",
".",
"customPages",
".",
"get",
"(",
"status",
")",
";",
"Object",
"customPage",
"=",
"CustomErrorPages",
".",
"getInstance",
"(",
")",
".",
"getDefaultFor",
"(",
"status",
")",
";",
"if",
"(",
"customRenderer",
"instanceof",
"String",
")",
"{",
"customPage",
"=",
"customRenderer",
";",
"}",
"else",
"if",
"(",
"customRenderer",
"instanceof",
"Route",
")",
"{",
"try",
"{",
"customPage",
"=",
"(",
"(",
"Route",
")",
"customRenderer",
")",
".",
"handle",
"(",
"request",
",",
"response",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// The custom page renderer is causing an internal server error. Log exception as a warning and use default page instead",
"LOG",
".",
"warn",
"(",
"\"Custom error page handler for status code {} has thrown an exception: {}. Using default page instead.\"",
",",
"status",
",",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"return",
"customPage",
";",
"}"
] |
Gets the custom error page for a given status code. If the custom
error page is a route, the output of its handle method is returned.
If the custom error page is a String, it is returned as an Object.
@param status
@param request
@param response
@return Object representing the custom error page
|
[
"Gets",
"the",
"custom",
"error",
"page",
"for",
"a",
"given",
"status",
"code",
".",
"If",
"the",
"custom",
"error",
"page",
"is",
"a",
"route",
"the",
"output",
"of",
"its",
"handle",
"method",
"is",
"returned",
".",
"If",
"the",
"custom",
"error",
"page",
"is",
"a",
"String",
"it",
"is",
"returned",
"as",
"an",
"Object",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/CustomErrorPages.java#L54-L71
|
13,766
|
perwendel/spark
|
src/main/java/spark/CustomErrorPages.java
|
CustomErrorPages.getDefaultFor
|
public String getDefaultFor(int status){
String defaultPage = defaultPages.get(status);
return (defaultPage != null) ? defaultPage : "<html><body><h2>HTTP Status " + status + "</h2></body></html>";
}
|
java
|
public String getDefaultFor(int status){
String defaultPage = defaultPages.get(status);
return (defaultPage != null) ? defaultPage : "<html><body><h2>HTTP Status " + status + "</h2></body></html>";
}
|
[
"public",
"String",
"getDefaultFor",
"(",
"int",
"status",
")",
"{",
"String",
"defaultPage",
"=",
"defaultPages",
".",
"get",
"(",
"status",
")",
";",
"return",
"(",
"defaultPage",
"!=",
"null",
")",
"?",
"defaultPage",
":",
"\"<html><body><h2>HTTP Status \"",
"+",
"status",
"+",
"\"</h2></body></html>\"",
";",
"}"
] |
Returns the default error page for a given status code.
Guaranteed to never be null.
@param status
@return String representation of the default error page.
|
[
"Returns",
"the",
"default",
"error",
"page",
"for",
"a",
"given",
"status",
"code",
".",
"Guaranteed",
"to",
"never",
"be",
"null",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/CustomErrorPages.java#L79-L82
|
13,767
|
perwendel/spark
|
src/main/java/spark/CustomErrorPages.java
|
CustomErrorPages.add
|
static void add(int status, String page) {
CustomErrorPages.getInstance().customPages.put(status, page);
}
|
java
|
static void add(int status, String page) {
CustomErrorPages.getInstance().customPages.put(status, page);
}
|
[
"static",
"void",
"add",
"(",
"int",
"status",
",",
"String",
"page",
")",
"{",
"CustomErrorPages",
".",
"getInstance",
"(",
")",
".",
"customPages",
".",
"put",
"(",
"status",
",",
"page",
")",
";",
"}"
] |
Add a custom error page as a String
@param status
@param page
|
[
"Add",
"a",
"custom",
"error",
"page",
"as",
"a",
"String"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/CustomErrorPages.java#L89-L91
|
13,768
|
perwendel/spark
|
src/main/java/spark/CustomErrorPages.java
|
CustomErrorPages.add
|
static void add(int status, Route route) {
CustomErrorPages.getInstance().customPages.put(status, route);
}
|
java
|
static void add(int status, Route route) {
CustomErrorPages.getInstance().customPages.put(status, route);
}
|
[
"static",
"void",
"add",
"(",
"int",
"status",
",",
"Route",
"route",
")",
"{",
"CustomErrorPages",
".",
"getInstance",
"(",
")",
".",
"customPages",
".",
"put",
"(",
"status",
",",
"route",
")",
";",
"}"
] |
Add a custom error page as a Route handler
@param status
@param route
|
[
"Add",
"a",
"custom",
"error",
"page",
"as",
"a",
"Route",
"handler"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/CustomErrorPages.java#L98-L100
|
13,769
|
perwendel/spark
|
src/main/java/spark/http/matching/Halt.java
|
Halt.modify
|
public static void modify(HttpServletResponse httpResponse, Body body, HaltException halt) {
httpResponse.setStatus(halt.statusCode());
if (halt.body() != null) {
body.set(halt.body());
} else {
body.set("");
}
}
|
java
|
public static void modify(HttpServletResponse httpResponse, Body body, HaltException halt) {
httpResponse.setStatus(halt.statusCode());
if (halt.body() != null) {
body.set(halt.body());
} else {
body.set("");
}
}
|
[
"public",
"static",
"void",
"modify",
"(",
"HttpServletResponse",
"httpResponse",
",",
"Body",
"body",
",",
"HaltException",
"halt",
")",
"{",
"httpResponse",
".",
"setStatus",
"(",
"halt",
".",
"statusCode",
"(",
")",
")",
";",
"if",
"(",
"halt",
".",
"body",
"(",
")",
"!=",
"null",
")",
"{",
"body",
".",
"set",
"(",
"halt",
".",
"body",
"(",
")",
")",
";",
"}",
"else",
"{",
"body",
".",
"set",
"(",
"\"\"",
")",
";",
"}",
"}"
] |
Modifies the HTTP response and body based on the provided HaltException.
@param httpResponse The HTTP servlet response
@param body The body content
@param halt The halt exception object
|
[
"Modifies",
"the",
"HTTP",
"response",
"and",
"body",
"based",
"on",
"the",
"provided",
"HaltException",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/http/matching/Halt.java#L35-L44
|
13,770
|
perwendel/spark
|
src/main/java/spark/Session.java
|
Session.attribute
|
@SuppressWarnings("unchecked")
public <T> T attribute(String name) {
return (T) session.getAttribute(name);
}
|
java
|
@SuppressWarnings("unchecked")
public <T> T attribute(String name) {
return (T) session.getAttribute(name);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"T",
">",
"T",
"attribute",
"(",
"String",
"name",
")",
"{",
"return",
"(",
"T",
")",
"session",
".",
"getAttribute",
"(",
"name",
")",
";",
"}"
] |
Returns the object bound with the specified name in this session, or null if no object is bound under the name.
@param name a string specifying the name of the object
@param <T> The type parameter
@return the object with the specified name
|
[
"Returns",
"the",
"object",
"bound",
"with",
"the",
"specified",
"name",
"in",
"this",
"session",
"or",
"null",
"if",
"no",
"object",
"is",
"bound",
"under",
"the",
"name",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Session.java#L47-L50
|
13,771
|
perwendel/spark
|
src/main/java/spark/Routable.java
|
Routable.after
|
public void after(Filter filter) {
addFilter(HttpMethod.after, FilterImpl.create(SparkUtils.ALL_PATHS, filter));
}
|
java
|
public void after(Filter filter) {
addFilter(HttpMethod.after, FilterImpl.create(SparkUtils.ALL_PATHS, filter));
}
|
[
"public",
"void",
"after",
"(",
"Filter",
"filter",
")",
"{",
"addFilter",
"(",
"HttpMethod",
".",
"after",
",",
"FilterImpl",
".",
"create",
"(",
"SparkUtils",
".",
"ALL_PATHS",
",",
"filter",
")",
")",
";",
"}"
] |
Maps a filter to be executed after any matching routes
@param filter The filter
|
[
"Maps",
"a",
"filter",
"to",
"be",
"executed",
"after",
"any",
"matching",
"routes"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Routable.java#L282-L284
|
13,772
|
perwendel/spark
|
src/main/java/spark/Routable.java
|
Routable.createRouteImpl
|
private RouteImpl createRouteImpl(String path, String acceptType, Route route) {
if (defaultResponseTransformer != null) {
return ResponseTransformerRouteImpl.create(path, acceptType, route, defaultResponseTransformer);
}
return RouteImpl.create(path, acceptType, route);
}
|
java
|
private RouteImpl createRouteImpl(String path, String acceptType, Route route) {
if (defaultResponseTransformer != null) {
return ResponseTransformerRouteImpl.create(path, acceptType, route, defaultResponseTransformer);
}
return RouteImpl.create(path, acceptType, route);
}
|
[
"private",
"RouteImpl",
"createRouteImpl",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Route",
"route",
")",
"{",
"if",
"(",
"defaultResponseTransformer",
"!=",
"null",
")",
"{",
"return",
"ResponseTransformerRouteImpl",
".",
"create",
"(",
"path",
",",
"acceptType",
",",
"route",
",",
"defaultResponseTransformer",
")",
";",
"}",
"return",
"RouteImpl",
".",
"create",
"(",
"path",
",",
"acceptType",
",",
"route",
")",
";",
"}"
] |
Create route implementation or use default response transformer
@param path the path
@param acceptType the accept type
@param route the route
@return ResponseTransformerRouteImpl or RouteImpl
|
[
"Create",
"route",
"implementation",
"or",
"use",
"default",
"response",
"transformer"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Routable.java#L806-L811
|
13,773
|
perwendel/spark
|
src/main/java/spark/embeddedserver/jetty/websocket/WebSocketServletContextHandlerFactory.java
|
WebSocketServletContextHandlerFactory.create
|
public static ServletContextHandler create(Map<String, WebSocketHandlerWrapper> webSocketHandlers,
Optional<Integer> webSocketIdleTimeoutMillis) {
ServletContextHandler webSocketServletContextHandler = null;
if (webSocketHandlers != null) {
try {
webSocketServletContextHandler = new ServletContextHandler(null, "/", true, false);
WebSocketUpgradeFilter webSocketUpgradeFilter = WebSocketUpgradeFilter.configureContext(webSocketServletContextHandler);
if (webSocketIdleTimeoutMillis.isPresent()) {
webSocketUpgradeFilter.getFactory().getPolicy().setIdleTimeout(webSocketIdleTimeoutMillis.get());
}
// Since we are configuring WebSockets before the ServletContextHandler and WebSocketUpgradeFilter is
// even initialized / started, then we have to pre-populate the configuration that will eventually
// be used by Jetty's WebSocketUpgradeFilter.
NativeWebSocketConfiguration webSocketConfiguration = (NativeWebSocketConfiguration) webSocketServletContextHandler
.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
for (String path : webSocketHandlers.keySet()) {
WebSocketCreator webSocketCreator = WebSocketCreatorFactory.create(webSocketHandlers.get(path));
webSocketConfiguration.addMapping(new ServletPathSpec(path), webSocketCreator);
}
} catch (Exception ex) {
logger.error("creation of websocket context handler failed.", ex);
webSocketServletContextHandler = null;
}
}
return webSocketServletContextHandler;
}
|
java
|
public static ServletContextHandler create(Map<String, WebSocketHandlerWrapper> webSocketHandlers,
Optional<Integer> webSocketIdleTimeoutMillis) {
ServletContextHandler webSocketServletContextHandler = null;
if (webSocketHandlers != null) {
try {
webSocketServletContextHandler = new ServletContextHandler(null, "/", true, false);
WebSocketUpgradeFilter webSocketUpgradeFilter = WebSocketUpgradeFilter.configureContext(webSocketServletContextHandler);
if (webSocketIdleTimeoutMillis.isPresent()) {
webSocketUpgradeFilter.getFactory().getPolicy().setIdleTimeout(webSocketIdleTimeoutMillis.get());
}
// Since we are configuring WebSockets before the ServletContextHandler and WebSocketUpgradeFilter is
// even initialized / started, then we have to pre-populate the configuration that will eventually
// be used by Jetty's WebSocketUpgradeFilter.
NativeWebSocketConfiguration webSocketConfiguration = (NativeWebSocketConfiguration) webSocketServletContextHandler
.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
for (String path : webSocketHandlers.keySet()) {
WebSocketCreator webSocketCreator = WebSocketCreatorFactory.create(webSocketHandlers.get(path));
webSocketConfiguration.addMapping(new ServletPathSpec(path), webSocketCreator);
}
} catch (Exception ex) {
logger.error("creation of websocket context handler failed.", ex);
webSocketServletContextHandler = null;
}
}
return webSocketServletContextHandler;
}
|
[
"public",
"static",
"ServletContextHandler",
"create",
"(",
"Map",
"<",
"String",
",",
"WebSocketHandlerWrapper",
">",
"webSocketHandlers",
",",
"Optional",
"<",
"Integer",
">",
"webSocketIdleTimeoutMillis",
")",
"{",
"ServletContextHandler",
"webSocketServletContextHandler",
"=",
"null",
";",
"if",
"(",
"webSocketHandlers",
"!=",
"null",
")",
"{",
"try",
"{",
"webSocketServletContextHandler",
"=",
"new",
"ServletContextHandler",
"(",
"null",
",",
"\"/\"",
",",
"true",
",",
"false",
")",
";",
"WebSocketUpgradeFilter",
"webSocketUpgradeFilter",
"=",
"WebSocketUpgradeFilter",
".",
"configureContext",
"(",
"webSocketServletContextHandler",
")",
";",
"if",
"(",
"webSocketIdleTimeoutMillis",
".",
"isPresent",
"(",
")",
")",
"{",
"webSocketUpgradeFilter",
".",
"getFactory",
"(",
")",
".",
"getPolicy",
"(",
")",
".",
"setIdleTimeout",
"(",
"webSocketIdleTimeoutMillis",
".",
"get",
"(",
")",
")",
";",
"}",
"// Since we are configuring WebSockets before the ServletContextHandler and WebSocketUpgradeFilter is",
"// even initialized / started, then we have to pre-populate the configuration that will eventually",
"// be used by Jetty's WebSocketUpgradeFilter.",
"NativeWebSocketConfiguration",
"webSocketConfiguration",
"=",
"(",
"NativeWebSocketConfiguration",
")",
"webSocketServletContextHandler",
".",
"getServletContext",
"(",
")",
".",
"getAttribute",
"(",
"NativeWebSocketConfiguration",
".",
"class",
".",
"getName",
"(",
")",
")",
";",
"for",
"(",
"String",
"path",
":",
"webSocketHandlers",
".",
"keySet",
"(",
")",
")",
"{",
"WebSocketCreator",
"webSocketCreator",
"=",
"WebSocketCreatorFactory",
".",
"create",
"(",
"webSocketHandlers",
".",
"get",
"(",
"path",
")",
")",
";",
"webSocketConfiguration",
".",
"addMapping",
"(",
"new",
"ServletPathSpec",
"(",
"path",
")",
",",
"webSocketCreator",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"logger",
".",
"error",
"(",
"\"creation of websocket context handler failed.\"",
",",
"ex",
")",
";",
"webSocketServletContextHandler",
"=",
"null",
";",
"}",
"}",
"return",
"webSocketServletContextHandler",
";",
"}"
] |
Creates a new websocket servlet context handler.
@param webSocketHandlers webSocketHandlers
@param webSocketIdleTimeoutMillis webSocketIdleTimeoutMillis
@return a new websocket servlet context handler or 'null' if creation failed.
|
[
"Creates",
"a",
"new",
"websocket",
"servlet",
"context",
"handler",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/embeddedserver/jetty/websocket/WebSocketServletContextHandlerFactory.java#L44-L69
|
13,774
|
perwendel/spark
|
src/main/java/spark/embeddedserver/EmbeddedServers.java
|
EmbeddedServers.create
|
public static EmbeddedServer create(Object identifier,
Routes routeMatcher,
ExceptionMapper exceptionMapper,
StaticFilesConfiguration staticFilesConfiguration,
boolean multipleHandlers) {
EmbeddedServerFactory factory = factories.get(identifier);
if (factory != null) {
return factory.create(routeMatcher, staticFilesConfiguration, exceptionMapper, multipleHandlers);
} else {
throw new RuntimeException("No embedded server matching the identifier");
}
}
|
java
|
public static EmbeddedServer create(Object identifier,
Routes routeMatcher,
ExceptionMapper exceptionMapper,
StaticFilesConfiguration staticFilesConfiguration,
boolean multipleHandlers) {
EmbeddedServerFactory factory = factories.get(identifier);
if (factory != null) {
return factory.create(routeMatcher, staticFilesConfiguration, exceptionMapper, multipleHandlers);
} else {
throw new RuntimeException("No embedded server matching the identifier");
}
}
|
[
"public",
"static",
"EmbeddedServer",
"create",
"(",
"Object",
"identifier",
",",
"Routes",
"routeMatcher",
",",
"ExceptionMapper",
"exceptionMapper",
",",
"StaticFilesConfiguration",
"staticFilesConfiguration",
",",
"boolean",
"multipleHandlers",
")",
"{",
"EmbeddedServerFactory",
"factory",
"=",
"factories",
".",
"get",
"(",
"identifier",
")",
";",
"if",
"(",
"factory",
"!=",
"null",
")",
"{",
"return",
"factory",
".",
"create",
"(",
"routeMatcher",
",",
"staticFilesConfiguration",
",",
"exceptionMapper",
",",
"multipleHandlers",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"No embedded server matching the identifier\"",
")",
";",
"}",
"}"
] |
Creates an embedded server of type corresponding to the provided identifier.
@param identifier the identifier
@param routeMatcher the route matcher
@param staticFilesConfiguration the static files configuration object
@param multipleHandlers true if other handlers exist
@return the created EmbeddedServer object
|
[
"Creates",
"an",
"embedded",
"server",
"of",
"type",
"corresponding",
"to",
"the",
"provided",
"identifier",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/embeddedserver/EmbeddedServers.java#L71-L84
|
13,775
|
perwendel/spark
|
src/main/java/spark/Response.java
|
Response.redirect
|
public void redirect(String location) {
if (LOG.isDebugEnabled()) {
LOG.debug("Redirecting ({} {} to {}", "Found", HttpServletResponse.SC_FOUND, location);
}
try {
response.sendRedirect(location);
} catch (IOException ioException) {
LOG.warn("Redirect failure", ioException);
}
}
|
java
|
public void redirect(String location) {
if (LOG.isDebugEnabled()) {
LOG.debug("Redirecting ({} {} to {}", "Found", HttpServletResponse.SC_FOUND, location);
}
try {
response.sendRedirect(location);
} catch (IOException ioException) {
LOG.warn("Redirect failure", ioException);
}
}
|
[
"public",
"void",
"redirect",
"(",
"String",
"location",
")",
"{",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Redirecting ({} {} to {}\"",
",",
"\"Found\"",
",",
"HttpServletResponse",
".",
"SC_FOUND",
",",
"location",
")",
";",
"}",
"try",
"{",
"response",
".",
"sendRedirect",
"(",
"location",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioException",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Redirect failure\"",
",",
"ioException",
")",
";",
"}",
"}"
] |
Trigger a browser redirect
@param location Where to redirect
|
[
"Trigger",
"a",
"browser",
"redirect"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Response.java#L117-L126
|
13,776
|
perwendel/spark
|
src/main/java/spark/Response.java
|
Response.redirect
|
public void redirect(String location, int httpStatusCode) {
if (LOG.isDebugEnabled()) {
LOG.debug("Redirecting ({} to {}", httpStatusCode, location);
}
response.setStatus(httpStatusCode);
response.setHeader("Location", location);
response.setHeader("Connection", "close");
try {
response.sendError(httpStatusCode);
} catch (IOException e) {
LOG.warn("Exception when trying to redirect permanently", e);
}
}
|
java
|
public void redirect(String location, int httpStatusCode) {
if (LOG.isDebugEnabled()) {
LOG.debug("Redirecting ({} to {}", httpStatusCode, location);
}
response.setStatus(httpStatusCode);
response.setHeader("Location", location);
response.setHeader("Connection", "close");
try {
response.sendError(httpStatusCode);
} catch (IOException e) {
LOG.warn("Exception when trying to redirect permanently", e);
}
}
|
[
"public",
"void",
"redirect",
"(",
"String",
"location",
",",
"int",
"httpStatusCode",
")",
"{",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Redirecting ({} to {}\"",
",",
"httpStatusCode",
",",
"location",
")",
";",
"}",
"response",
".",
"setStatus",
"(",
"httpStatusCode",
")",
";",
"response",
".",
"setHeader",
"(",
"\"Location\"",
",",
"location",
")",
";",
"response",
".",
"setHeader",
"(",
"\"Connection\"",
",",
"\"close\"",
")",
";",
"try",
"{",
"response",
".",
"sendError",
"(",
"httpStatusCode",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Exception when trying to redirect permanently\"",
",",
"e",
")",
";",
"}",
"}"
] |
Trigger a browser redirect with specific http 3XX status code.
@param location Where to redirect permanently
@param httpStatusCode the http status code
|
[
"Trigger",
"a",
"browser",
"redirect",
"with",
"specific",
"http",
"3XX",
"status",
"code",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Response.java#L134-L146
|
13,777
|
perwendel/spark
|
src/main/java/spark/Response.java
|
Response.removeCookie
|
public void removeCookie(String path, String name) {
Cookie cookie = new Cookie(name, "");
cookie.setPath(path);
cookie.setMaxAge(0);
response.addCookie(cookie);
}
|
java
|
public void removeCookie(String path, String name) {
Cookie cookie = new Cookie(name, "");
cookie.setPath(path);
cookie.setMaxAge(0);
response.addCookie(cookie);
}
|
[
"public",
"void",
"removeCookie",
"(",
"String",
"path",
",",
"String",
"name",
")",
"{",
"Cookie",
"cookie",
"=",
"new",
"Cookie",
"(",
"name",
",",
"\"\"",
")",
";",
"cookie",
".",
"setPath",
"(",
"path",
")",
";",
"cookie",
".",
"setMaxAge",
"(",
"0",
")",
";",
"response",
".",
"addCookie",
"(",
"cookie",
")",
";",
"}"
] |
Removes the cookie with given path and name.
@param path path of the cookie
@param name name of the cookie
|
[
"Removes",
"the",
"cookie",
"with",
"given",
"path",
"and",
"name",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Response.java#L269-L274
|
13,778
|
perwendel/spark
|
src/main/java/spark/QueryParamsMap.java
|
QueryParamsMap.loadQueryString
|
protected final void loadQueryString(Map<String, String[]> params) {
for (Map.Entry<String, String[]> param : params.entrySet()) {
loadKeys(param.getKey(), param.getValue());
}
}
|
java
|
protected final void loadQueryString(Map<String, String[]> params) {
for (Map.Entry<String, String[]> param : params.entrySet()) {
loadKeys(param.getKey(), param.getValue());
}
}
|
[
"protected",
"final",
"void",
"loadQueryString",
"(",
"Map",
"<",
"String",
",",
"String",
"[",
"]",
">",
"params",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
"[",
"]",
">",
"param",
":",
"params",
".",
"entrySet",
"(",
")",
")",
"{",
"loadKeys",
"(",
"param",
".",
"getKey",
"(",
")",
",",
"param",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}"
] |
loads query string
@param params the parameters
|
[
"loads",
"query",
"string"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/QueryParamsMap.java#L97-L101
|
13,779
|
perwendel/spark
|
src/main/java/spark/staticfiles/StaticFilesConfiguration.java
|
StaticFilesConfiguration.consume
|
public boolean consume(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) throws IOException {
try {
if (consumeWithFileResourceHandlers(httpRequest, httpResponse)) {
return true;
}
} catch (DirectoryTraversal.DirectoryTraversalDetection directoryTraversalDetection) {
httpResponse.setStatus(400);
httpResponse.getWriter().write("Bad request");
httpResponse.getWriter().flush();
LOG.warn(directoryTraversalDetection.getMessage() + " directory traversal detection for path: "
+ httpRequest.getPathInfo());
}
return false;
}
|
java
|
public boolean consume(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) throws IOException {
try {
if (consumeWithFileResourceHandlers(httpRequest, httpResponse)) {
return true;
}
} catch (DirectoryTraversal.DirectoryTraversalDetection directoryTraversalDetection) {
httpResponse.setStatus(400);
httpResponse.getWriter().write("Bad request");
httpResponse.getWriter().flush();
LOG.warn(directoryTraversalDetection.getMessage() + " directory traversal detection for path: "
+ httpRequest.getPathInfo());
}
return false;
}
|
[
"public",
"boolean",
"consume",
"(",
"HttpServletRequest",
"httpRequest",
",",
"HttpServletResponse",
"httpResponse",
")",
"throws",
"IOException",
"{",
"try",
"{",
"if",
"(",
"consumeWithFileResourceHandlers",
"(",
"httpRequest",
",",
"httpResponse",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"catch",
"(",
"DirectoryTraversal",
".",
"DirectoryTraversalDetection",
"directoryTraversalDetection",
")",
"{",
"httpResponse",
".",
"setStatus",
"(",
"400",
")",
";",
"httpResponse",
".",
"getWriter",
"(",
")",
".",
"write",
"(",
"\"Bad request\"",
")",
";",
"httpResponse",
".",
"getWriter",
"(",
")",
".",
"flush",
"(",
")",
";",
"LOG",
".",
"warn",
"(",
"directoryTraversalDetection",
".",
"getMessage",
"(",
")",
"+",
"\" directory traversal detection for path: \"",
"+",
"httpRequest",
".",
"getPathInfo",
"(",
")",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Attempt consuming using either static resource handlers or jar resource handlers
@param httpRequest The HTTP servlet request.
@param httpResponse The HTTP servlet response.
@return true if consumed, false otherwise.
@throws IOException in case of IO error.
|
[
"Attempt",
"consuming",
"using",
"either",
"static",
"resource",
"handlers",
"or",
"jar",
"resource",
"handlers"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/staticfiles/StaticFilesConfiguration.java#L67-L82
|
13,780
|
perwendel/spark
|
src/main/java/spark/staticfiles/StaticFilesConfiguration.java
|
StaticFilesConfiguration.clear
|
public void clear() {
if (staticResourceHandlers != null) {
staticResourceHandlers.clear();
staticResourceHandlers = null;
}
staticResourcesSet = false;
externalStaticResourcesSet = false;
}
|
java
|
public void clear() {
if (staticResourceHandlers != null) {
staticResourceHandlers.clear();
staticResourceHandlers = null;
}
staticResourcesSet = false;
externalStaticResourcesSet = false;
}
|
[
"public",
"void",
"clear",
"(",
")",
"{",
"if",
"(",
"staticResourceHandlers",
"!=",
"null",
")",
"{",
"staticResourceHandlers",
".",
"clear",
"(",
")",
";",
"staticResourceHandlers",
"=",
"null",
";",
"}",
"staticResourcesSet",
"=",
"false",
";",
"externalStaticResourcesSet",
"=",
"false",
";",
"}"
] |
Clears all static file configuration
|
[
"Clears",
"all",
"static",
"file",
"configuration"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/staticfiles/StaticFilesConfiguration.java#L116-L125
|
13,781
|
perwendel/spark
|
src/main/java/spark/utils/MimeParse.java
|
MimeParse.bestMatch
|
public static String bestMatch(Collection<String> supported, String header) {
List<ParseResults> parseResults = new LinkedList<>();
List<FitnessAndQuality> weightedMatches = new LinkedList<>();
for (String r : header.split(",")) {
parseResults.add(parseMediaRange(r));
}
for (String s : supported) {
FitnessAndQuality fitnessAndQuality = fitnessAndQualityParsed(s, parseResults);
fitnessAndQuality.mimeType = s;
weightedMatches.add(fitnessAndQuality);
}
Collections.sort(weightedMatches);
FitnessAndQuality lastOne = weightedMatches.get(weightedMatches.size() - 1);
return Float.compare(lastOne.quality, 0) != 0 ? lastOne.mimeType : NO_MIME_TYPE;
}
|
java
|
public static String bestMatch(Collection<String> supported, String header) {
List<ParseResults> parseResults = new LinkedList<>();
List<FitnessAndQuality> weightedMatches = new LinkedList<>();
for (String r : header.split(",")) {
parseResults.add(parseMediaRange(r));
}
for (String s : supported) {
FitnessAndQuality fitnessAndQuality = fitnessAndQualityParsed(s, parseResults);
fitnessAndQuality.mimeType = s;
weightedMatches.add(fitnessAndQuality);
}
Collections.sort(weightedMatches);
FitnessAndQuality lastOne = weightedMatches.get(weightedMatches.size() - 1);
return Float.compare(lastOne.quality, 0) != 0 ? lastOne.mimeType : NO_MIME_TYPE;
}
|
[
"public",
"static",
"String",
"bestMatch",
"(",
"Collection",
"<",
"String",
">",
"supported",
",",
"String",
"header",
")",
"{",
"List",
"<",
"ParseResults",
">",
"parseResults",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"List",
"<",
"FitnessAndQuality",
">",
"weightedMatches",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"r",
":",
"header",
".",
"split",
"(",
"\",\"",
")",
")",
"{",
"parseResults",
".",
"add",
"(",
"parseMediaRange",
"(",
"r",
")",
")",
";",
"}",
"for",
"(",
"String",
"s",
":",
"supported",
")",
"{",
"FitnessAndQuality",
"fitnessAndQuality",
"=",
"fitnessAndQualityParsed",
"(",
"s",
",",
"parseResults",
")",
";",
"fitnessAndQuality",
".",
"mimeType",
"=",
"s",
";",
"weightedMatches",
".",
"add",
"(",
"fitnessAndQuality",
")",
";",
"}",
"Collections",
".",
"sort",
"(",
"weightedMatches",
")",
";",
"FitnessAndQuality",
"lastOne",
"=",
"weightedMatches",
".",
"get",
"(",
"weightedMatches",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"return",
"Float",
".",
"compare",
"(",
"lastOne",
".",
"quality",
",",
"0",
")",
"!=",
"0",
"?",
"lastOne",
".",
"mimeType",
":",
"NO_MIME_TYPE",
";",
"}"
] |
Finds best match
@param supported the supported types
@param header the header
@return the best match
|
[
"Finds",
"best",
"match"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/utils/MimeParse.java#L173-L189
|
13,782
|
perwendel/spark
|
src/main/java/spark/Redirect.java
|
Redirect.any
|
public void any(String fromPath, String toPath, Status status) {
get(fromPath, toPath, status);
post(fromPath, toPath, status);
put(fromPath, toPath, status);
delete(fromPath, toPath, status);
}
|
java
|
public void any(String fromPath, String toPath, Status status) {
get(fromPath, toPath, status);
post(fromPath, toPath, status);
put(fromPath, toPath, status);
delete(fromPath, toPath, status);
}
|
[
"public",
"void",
"any",
"(",
"String",
"fromPath",
",",
"String",
"toPath",
",",
"Status",
"status",
")",
"{",
"get",
"(",
"fromPath",
",",
"toPath",
",",
"status",
")",
";",
"post",
"(",
"fromPath",
",",
"toPath",
",",
"status",
")",
";",
"put",
"(",
"fromPath",
",",
"toPath",
",",
"status",
")",
";",
"delete",
"(",
"fromPath",
",",
"toPath",
",",
"status",
")",
";",
"}"
] |
Redirects any HTTP request of type GET, POST, PUT, DELETE on 'fromPath' to 'toPath' with the provided redirect
'status' code.
@param fromPath from path
@param toPath to path
@param status status code
|
[
"Redirects",
"any",
"HTTP",
"request",
"of",
"type",
"GET",
"POST",
"PUT",
"DELETE",
"on",
"fromPath",
"to",
"toPath",
"with",
"the",
"provided",
"redirect",
"status",
"code",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Redirect.java#L120-L125
|
13,783
|
perwendel/spark
|
src/main/java/spark/Redirect.java
|
Redirect.get
|
public void get(String fromPath, String toPath, Status status) {
http.get(fromPath, redirectRoute(toPath, status));
}
|
java
|
public void get(String fromPath, String toPath, Status status) {
http.get(fromPath, redirectRoute(toPath, status));
}
|
[
"public",
"void",
"get",
"(",
"String",
"fromPath",
",",
"String",
"toPath",
",",
"Status",
"status",
")",
"{",
"http",
".",
"get",
"(",
"fromPath",
",",
"redirectRoute",
"(",
"toPath",
",",
"status",
")",
")",
";",
"}"
] |
Redirects any HTTP request of type GET on 'fromPath' to 'toPath' with the provided redirect 'status' code.
@param fromPath from path
@param toPath to path
@param status status code
|
[
"Redirects",
"any",
"HTTP",
"request",
"of",
"type",
"GET",
"on",
"fromPath",
"to",
"toPath",
"with",
"the",
"provided",
"redirect",
"status",
"code",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Redirect.java#L134-L136
|
13,784
|
perwendel/spark
|
src/main/java/spark/Redirect.java
|
Redirect.post
|
public void post(String fromPath, String toPath, Status status) {
http.post(fromPath, redirectRoute(toPath, status));
}
|
java
|
public void post(String fromPath, String toPath, Status status) {
http.post(fromPath, redirectRoute(toPath, status));
}
|
[
"public",
"void",
"post",
"(",
"String",
"fromPath",
",",
"String",
"toPath",
",",
"Status",
"status",
")",
"{",
"http",
".",
"post",
"(",
"fromPath",
",",
"redirectRoute",
"(",
"toPath",
",",
"status",
")",
")",
";",
"}"
] |
Redirects any HTTP request of type POST on 'fromPath' to 'toPath' with the provided redirect 'status' code.
@param fromPath from path
@param toPath to path
@param status status code
|
[
"Redirects",
"any",
"HTTP",
"request",
"of",
"type",
"POST",
"on",
"fromPath",
"to",
"toPath",
"with",
"the",
"provided",
"redirect",
"status",
"code",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Redirect.java#L145-L147
|
13,785
|
perwendel/spark
|
src/main/java/spark/Redirect.java
|
Redirect.put
|
public void put(String fromPath, String toPath, Status status) {
http.put(fromPath, redirectRoute(toPath, status));
}
|
java
|
public void put(String fromPath, String toPath, Status status) {
http.put(fromPath, redirectRoute(toPath, status));
}
|
[
"public",
"void",
"put",
"(",
"String",
"fromPath",
",",
"String",
"toPath",
",",
"Status",
"status",
")",
"{",
"http",
".",
"put",
"(",
"fromPath",
",",
"redirectRoute",
"(",
"toPath",
",",
"status",
")",
")",
";",
"}"
] |
Redirects any HTTP request of type PUT on 'fromPath' to 'toPath' with the provided redirect 'status' code.
@param fromPath from path
@param toPath to path
@param status status code
|
[
"Redirects",
"any",
"HTTP",
"request",
"of",
"type",
"PUT",
"on",
"fromPath",
"to",
"toPath",
"with",
"the",
"provided",
"redirect",
"status",
"code",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Redirect.java#L156-L158
|
13,786
|
perwendel/spark
|
src/main/java/spark/Redirect.java
|
Redirect.delete
|
public void delete(String fromPath, String toPath, Status status) {
http.delete(fromPath, redirectRoute(toPath, status));
}
|
java
|
public void delete(String fromPath, String toPath, Status status) {
http.delete(fromPath, redirectRoute(toPath, status));
}
|
[
"public",
"void",
"delete",
"(",
"String",
"fromPath",
",",
"String",
"toPath",
",",
"Status",
"status",
")",
"{",
"http",
".",
"delete",
"(",
"fromPath",
",",
"redirectRoute",
"(",
"toPath",
",",
"status",
")",
")",
";",
"}"
] |
Redirects any HTTP request of type DELETE on 'fromPath' to 'toPath' with the provided redirect 'status' code.
@param fromPath from path
@param toPath to path
@param status status code
|
[
"Redirects",
"any",
"HTTP",
"request",
"of",
"type",
"DELETE",
"on",
"fromPath",
"to",
"toPath",
"with",
"the",
"provided",
"redirect",
"status",
"code",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Redirect.java#L167-L169
|
13,787
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.put
|
public static void put(String path, String acceptType, Route route) {
getInstance().put(path, acceptType, route);
}
|
java
|
public static void put(String path, String acceptType, Route route) {
getInstance().put(path, acceptType, route);
}
|
[
"public",
"static",
"void",
"put",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Route",
"route",
")",
"{",
"getInstance",
"(",
")",
".",
"put",
"(",
"path",
",",
"acceptType",
",",
"route",
")",
";",
"}"
] |
Map the route for HTTP PUT requests
@param path the path
@param acceptType the accept type
@param route The route
|
[
"Map",
"the",
"route",
"for",
"HTTP",
"PUT",
"requests"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L256-L258
|
13,788
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.patch
|
public static void patch(String path, String acceptType, Route route) {
getInstance().patch(path, acceptType, route);
}
|
java
|
public static void patch(String path, String acceptType, Route route) {
getInstance().patch(path, acceptType, route);
}
|
[
"public",
"static",
"void",
"patch",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Route",
"route",
")",
"{",
"getInstance",
"(",
")",
".",
"patch",
"(",
"path",
",",
"acceptType",
",",
"route",
")",
";",
"}"
] |
Map the route for HTTP PATCH requests
@param path the path
@param acceptType the accept type
@param route The route
|
[
"Map",
"the",
"route",
"for",
"HTTP",
"PATCH",
"requests"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L267-L269
|
13,789
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.trace
|
public static void trace(String path, String acceptType, Route route) {
getInstance().trace(path, acceptType, route);
}
|
java
|
public static void trace(String path, String acceptType, Route route) {
getInstance().trace(path, acceptType, route);
}
|
[
"public",
"static",
"void",
"trace",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Route",
"route",
")",
"{",
"getInstance",
"(",
")",
".",
"trace",
"(",
"path",
",",
"acceptType",
",",
"route",
")",
";",
"}"
] |
Map the route for HTTP TRACE requests
@param path the path
@param acceptType the accept type
@param route The route
|
[
"Map",
"the",
"route",
"for",
"HTTP",
"TRACE",
"requests"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L300-L302
|
13,790
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.connect
|
public static void connect(String path, String acceptType, Route route) {
getInstance().connect(path, acceptType, route);
}
|
java
|
public static void connect(String path, String acceptType, Route route) {
getInstance().connect(path, acceptType, route);
}
|
[
"public",
"static",
"void",
"connect",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Route",
"route",
")",
"{",
"getInstance",
"(",
")",
".",
"connect",
"(",
"path",
",",
"acceptType",
",",
"route",
")",
";",
"}"
] |
Map the route for HTTP CONNECT requests
@param path the path
@param acceptType the accept type
@param route The route
|
[
"Map",
"the",
"route",
"for",
"HTTP",
"CONNECT",
"requests"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L311-L313
|
13,791
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.options
|
public static void options(String path, String acceptType, Route route) {
getInstance().options(path, acceptType, route);
}
|
java
|
public static void options(String path, String acceptType, Route route) {
getInstance().options(path, acceptType, route);
}
|
[
"public",
"static",
"void",
"options",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Route",
"route",
")",
"{",
"getInstance",
"(",
")",
".",
"options",
"(",
"path",
",",
"acceptType",
",",
"route",
")",
";",
"}"
] |
Map the route for HTTP OPTIONS requests
@param path the path
@param acceptType the accept type
@param route The route
|
[
"Map",
"the",
"route",
"for",
"HTTP",
"OPTIONS",
"requests"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L322-L324
|
13,792
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.before
|
public static void before(String path, String acceptType, Filter... filters) {
for (Filter filter : filters) {
getInstance().before(path, acceptType, filter);
}
}
|
java
|
public static void before(String path, String acceptType, Filter... filters) {
for (Filter filter : filters) {
getInstance().before(path, acceptType, filter);
}
}
|
[
"public",
"static",
"void",
"before",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Filter",
"...",
"filters",
")",
"{",
"for",
"(",
"Filter",
"filter",
":",
"filters",
")",
"{",
"getInstance",
"(",
")",
".",
"before",
"(",
"path",
",",
"acceptType",
",",
"filter",
")",
";",
"}",
"}"
] |
Maps one or many filters to be executed before any matching routes
@param path the path
@param acceptType the accept type
@param filters The filters
|
[
"Maps",
"one",
"or",
"many",
"filters",
"to",
"be",
"executed",
"before",
"any",
"matching",
"routes"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L356-L360
|
13,793
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.after
|
public static void after(String path, String acceptType, Filter... filters) {
for (Filter filter : filters) {
getInstance().after(path, acceptType, filter);
}
}
|
java
|
public static void after(String path, String acceptType, Filter... filters) {
for (Filter filter : filters) {
getInstance().after(path, acceptType, filter);
}
}
|
[
"public",
"static",
"void",
"after",
"(",
"String",
"path",
",",
"String",
"acceptType",
",",
"Filter",
"...",
"filters",
")",
"{",
"for",
"(",
"Filter",
"filter",
":",
"filters",
")",
"{",
"getInstance",
"(",
")",
".",
"after",
"(",
"path",
",",
"acceptType",
",",
"filter",
")",
";",
"}",
"}"
] |
Maps one or many filters to be executed after any matching routes
@param path the path
@param acceptType the accept type
@param filters The filters
|
[
"Maps",
"one",
"or",
"many",
"filters",
"to",
"be",
"executed",
"after",
"any",
"matching",
"routes"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L370-L374
|
13,794
|
perwendel/spark
|
src/main/java/spark/Spark.java
|
Spark.exception
|
public static <T extends Exception> void exception(Class<T> exceptionClass, ExceptionHandler<? super T> handler) {
getInstance().exception(exceptionClass, handler);
}
|
java
|
public static <T extends Exception> void exception(Class<T> exceptionClass, ExceptionHandler<? super T> handler) {
getInstance().exception(exceptionClass, handler);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Exception",
">",
"void",
"exception",
"(",
"Class",
"<",
"T",
">",
"exceptionClass",
",",
"ExceptionHandler",
"<",
"?",
"super",
"T",
">",
"handler",
")",
"{",
"getInstance",
"(",
")",
".",
"exception",
"(",
"exceptionClass",
",",
"handler",
")",
";",
"}"
] |
Maps an exception handler to be executed when an exception occurs during routing
@param exceptionClass the exception class
@param handler The handler
|
[
"Maps",
"an",
"exception",
"handler",
"to",
"be",
"executed",
"when",
"an",
"exception",
"occurs",
"during",
"routing"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Spark.java#L881-L883
|
13,795
|
perwendel/spark
|
src/main/java/spark/resource/ClassPathResource.java
|
ClassPathResource.exists
|
@Override
public boolean exists() {
URL url;
if (this.clazz != null) {
url = this.clazz.getResource(this.path);
} else {
url = this.classLoader.getResource(this.path);
}
return (url != null);
}
|
java
|
@Override
public boolean exists() {
URL url;
if (this.clazz != null) {
url = this.clazz.getResource(this.path);
} else {
url = this.classLoader.getResource(this.path);
}
return (url != null);
}
|
[
"@",
"Override",
"public",
"boolean",
"exists",
"(",
")",
"{",
"URL",
"url",
";",
"if",
"(",
"this",
".",
"clazz",
"!=",
"null",
")",
"{",
"url",
"=",
"this",
".",
"clazz",
".",
"getResource",
"(",
"this",
".",
"path",
")",
";",
"}",
"else",
"{",
"url",
"=",
"this",
".",
"classLoader",
".",
"getResource",
"(",
"this",
".",
"path",
")",
";",
"}",
"return",
"(",
"url",
"!=",
"null",
")",
";",
"}"
] |
This implementation checks for the resolution of a resource URL.
@return if exists.
@see java.lang.ClassLoader#getResource(String)
@see java.lang.Class#getResource(String)
|
[
"This",
"implementation",
"checks",
"for",
"the",
"resolution",
"of",
"a",
"resource",
"URL",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/resource/ClassPathResource.java#L143-L152
|
13,796
|
perwendel/spark
|
src/main/java/spark/resource/ClassPathResource.java
|
ClassPathResource.createRelative
|
@Override
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
}
|
java
|
@Override
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
}
|
[
"@",
"Override",
"public",
"Resource",
"createRelative",
"(",
"String",
"relativePath",
")",
"{",
"String",
"pathToUse",
"=",
"StringUtils",
".",
"applyRelativePath",
"(",
"this",
".",
"path",
",",
"relativePath",
")",
";",
"return",
"new",
"ClassPathResource",
"(",
"pathToUse",
",",
"this",
".",
"classLoader",
",",
"this",
".",
"clazz",
")",
";",
"}"
] |
This implementation creates a ClassPathResource, applying the given path
relative to the path of the underlying resource of this descriptor.
@return the resource.
@see spark.utils.StringUtils#applyRelativePath(String, String)
|
[
"This",
"implementation",
"creates",
"a",
"ClassPathResource",
"applying",
"the",
"given",
"path",
"relative",
"to",
"the",
"path",
"of",
"the",
"underlying",
"resource",
"of",
"this",
"descriptor",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/resource/ClassPathResource.java#L203-L207
|
13,797
|
perwendel/spark
|
src/main/java/spark/serialization/SerializerChain.java
|
SerializerChain.process
|
public void process(OutputStream outputStream, Object element) throws IOException {
this.root.processElement(outputStream, element);
}
|
java
|
public void process(OutputStream outputStream, Object element) throws IOException {
this.root.processElement(outputStream, element);
}
|
[
"public",
"void",
"process",
"(",
"OutputStream",
"outputStream",
",",
"Object",
"element",
")",
"throws",
"IOException",
"{",
"this",
".",
"root",
".",
"processElement",
"(",
"outputStream",
",",
"element",
")",
";",
"}"
] |
Process the output.
@param outputStream the output stream to write to.
@param element the element to serialize.
@throws IOException in the case of IO error.
|
[
"Process",
"the",
"output",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/serialization/SerializerChain.java#L52-L54
|
13,798
|
perwendel/spark
|
src/main/java/spark/http/matching/GeneralError.java
|
GeneralError.modify
|
static void modify(HttpServletRequest httpRequest,
HttpServletResponse httpResponse,
Body body,
RequestWrapper requestWrapper,
ResponseWrapper responseWrapper,
ExceptionMapper exceptionMapper,
Exception e) {
ExceptionHandlerImpl handler = exceptionMapper.getHandler(e);
if (handler != null) {
handler.handle(e, requestWrapper, responseWrapper);
String bodyAfterFilter = responseWrapper.getDelegate().body();
if (bodyAfterFilter != null) {
body.set(bodyAfterFilter);
}
} else {
LOG.error("", e);
httpResponse.setStatus(500);
if (CustomErrorPages.existsFor(500)) {
requestWrapper.setDelegate(RequestResponseFactory.create(httpRequest));
responseWrapper.setDelegate(RequestResponseFactory.create(httpResponse));
body.set(CustomErrorPages.getFor(500, requestWrapper, responseWrapper));
} else {
body.set(CustomErrorPages.INTERNAL_ERROR);
}
}
}
|
java
|
static void modify(HttpServletRequest httpRequest,
HttpServletResponse httpResponse,
Body body,
RequestWrapper requestWrapper,
ResponseWrapper responseWrapper,
ExceptionMapper exceptionMapper,
Exception e) {
ExceptionHandlerImpl handler = exceptionMapper.getHandler(e);
if (handler != null) {
handler.handle(e, requestWrapper, responseWrapper);
String bodyAfterFilter = responseWrapper.getDelegate().body();
if (bodyAfterFilter != null) {
body.set(bodyAfterFilter);
}
} else {
LOG.error("", e);
httpResponse.setStatus(500);
if (CustomErrorPages.existsFor(500)) {
requestWrapper.setDelegate(RequestResponseFactory.create(httpRequest));
responseWrapper.setDelegate(RequestResponseFactory.create(httpResponse));
body.set(CustomErrorPages.getFor(500, requestWrapper, responseWrapper));
} else {
body.set(CustomErrorPages.INTERNAL_ERROR);
}
}
}
|
[
"static",
"void",
"modify",
"(",
"HttpServletRequest",
"httpRequest",
",",
"HttpServletResponse",
"httpResponse",
",",
"Body",
"body",
",",
"RequestWrapper",
"requestWrapper",
",",
"ResponseWrapper",
"responseWrapper",
",",
"ExceptionMapper",
"exceptionMapper",
",",
"Exception",
"e",
")",
"{",
"ExceptionHandlerImpl",
"handler",
"=",
"exceptionMapper",
".",
"getHandler",
"(",
"e",
")",
";",
"if",
"(",
"handler",
"!=",
"null",
")",
"{",
"handler",
".",
"handle",
"(",
"e",
",",
"requestWrapper",
",",
"responseWrapper",
")",
";",
"String",
"bodyAfterFilter",
"=",
"responseWrapper",
".",
"getDelegate",
"(",
")",
".",
"body",
"(",
")",
";",
"if",
"(",
"bodyAfterFilter",
"!=",
"null",
")",
"{",
"body",
".",
"set",
"(",
"bodyAfterFilter",
")",
";",
"}",
"}",
"else",
"{",
"LOG",
".",
"error",
"(",
"\"\"",
",",
"e",
")",
";",
"httpResponse",
".",
"setStatus",
"(",
"500",
")",
";",
"if",
"(",
"CustomErrorPages",
".",
"existsFor",
"(",
"500",
")",
")",
"{",
"requestWrapper",
".",
"setDelegate",
"(",
"RequestResponseFactory",
".",
"create",
"(",
"httpRequest",
")",
")",
";",
"responseWrapper",
".",
"setDelegate",
"(",
"RequestResponseFactory",
".",
"create",
"(",
"httpResponse",
")",
")",
";",
"body",
".",
"set",
"(",
"CustomErrorPages",
".",
"getFor",
"(",
"500",
",",
"requestWrapper",
",",
"responseWrapper",
")",
")",
";",
"}",
"else",
"{",
"body",
".",
"set",
"(",
"CustomErrorPages",
".",
"INTERNAL_ERROR",
")",
";",
"}",
"}",
"}"
] |
Modifies the HTTP response and body based on the provided exception.
|
[
"Modifies",
"the",
"HTTP",
"response",
"and",
"body",
"based",
"on",
"the",
"provided",
"exception",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/http/matching/GeneralError.java#L37-L67
|
13,799
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.add
|
public void add(HttpMethod httpMethod, RouteImpl route) {
add(httpMethod, route.getPath() , route.getAcceptType(), route);
}
|
java
|
public void add(HttpMethod httpMethod, RouteImpl route) {
add(httpMethod, route.getPath() , route.getAcceptType(), route);
}
|
[
"public",
"void",
"add",
"(",
"HttpMethod",
"httpMethod",
",",
"RouteImpl",
"route",
")",
"{",
"add",
"(",
"httpMethod",
",",
"route",
".",
"getPath",
"(",
")",
",",
"route",
".",
"getAcceptType",
"(",
")",
",",
"route",
")",
";",
"}"
] |
Add a route
@param httpMethod the http-method of the route
@param route the route to add
|
[
"Add",
"a",
"route"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L61-L63
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.