net.opentsdb.tree
public final class Tree extends Object
Branch
and Leaf
objects while
meta data about the tree is contained in this object.
A tree is built from a set of TreeRule
s. The rules are stored
separately in the same row as the tree definition object, but can be loaded
into the tree for processing and return from an RPC request. Building a tree
consists of defining a tree, assigning one or more rules, and passing
TSMeta
objects through the rule set using a
TreeBuilder
. Results are then stored in separate rows as branch
and leaf objects.
If TSMeta collides with something that has already been processed by a
rule set, a collision will be recorded, via this object, in a separate column
in a separate row for collisions. Likewise, if a tree is set to
strict_match
, TSMetas that fail to match the rule set will be
recorded to a separate row. This class provides helper methods for fetching
and storing these collisions and non-matched items.
Constructor and Description |
---|
Tree()
Default constructor necessary for de/serialization
|
Tree(int tree_id)
Constructor that sets the tree ID and the created timestamp to the current
time.
|
Tree(Tree original)
Copy constructor that creates a completely independent copy of the original
object.
|
Modifier and Type | Method and Description |
---|---|
void |
addCollision(String tsuid,
String existing_tsuid)
Adds a TSUID to the collision local list, must then be synced with storage
|
void |
addNotMatched(String tsuid,
String message)
Adds a TSUID to the not-matched local list when strict_matching is enabled.
|
void |
addRule(TreeRule rule)
Adds the given rule to the tree, replacing anything in the designated spot
|
static int |
bytesToId(byte[] row_key)
Attempts to convert the given byte array into an integer tree ID
Note: You can give this method a full branch row key and it will
only parse out the first
TREE_ID_WIDTH bytes. |
static byte[] |
COLLISION_PREFIX() |
boolean |
copyChanges(Tree tree,
boolean overwrite)
Copies changes from the incoming tree into the local tree, overriding if
called to.
|
com.stumbleupon.async.Deferred<Integer> |
createNewTree(TSDB tsdb)
Attempts to store the local tree in a new row, automatically assigning a
new tree ID and returning the value.
|
static com.stumbleupon.async.Deferred<Boolean> |
deleteTree(TSDB tsdb,
int tree_id,
boolean delete_definition)
Attempts to delete all branches, leaves, collisions and not-matched entries
for the given tree.
|
static com.stumbleupon.async.Deferred<List<Tree>> |
fetchAllTrees(TSDB tsdb)
Attempts to retrieve all trees from the UID table, including their rules.
|
static com.stumbleupon.async.Deferred<Map<String,String>> |
fetchCollisions(TSDB tsdb,
int tree_id,
List<String> tsuids)
Returns the collision set from storage for the given tree, optionally for
only the list of TSUIDs provided.
|
static com.stumbleupon.async.Deferred<Map<String,String>> |
fetchNotMatched(TSDB tsdb,
int tree_id,
List<String> tsuids)
Returns the not-matched set from storage for the given tree, optionally for
only the list of TSUIDs provided.
|
static com.stumbleupon.async.Deferred<Tree> |
fetchTree(TSDB tsdb,
int tree_id)
Attempts to fetch the given tree from storage, loading the rule set at
the same time.
|
com.stumbleupon.async.Deferred<Boolean> |
flushCollisions(TSDB tsdb)
Attempts to flush the collisions to storage.
|
com.stumbleupon.async.Deferred<Boolean> |
flushNotMatched(TSDB tsdb)
Attempts to flush the non-matches to storage.
|
Map<String,String> |
getCollisions() |
long |
getCreated() |
String |
getDescription() |
boolean |
getEnabled() |
String |
getName() |
String |
getNotes() |
Map<String,String> |
getNotMatched() |
TreeRule |
getRule(int level,
int order)
Retrieves a single rule from the rule set given a level and order
|
Map<Integer,TreeMap<Integer,TreeRule>> |
getRules() |
boolean |
getStoreFailures() |
boolean |
getStrictMatch() |
int |
getTreeId() |
static byte[] |
idToBytes(int tree_id)
Converts the tree ID into a byte array
TREE_ID_WIDTH in size |
static byte[] |
NOT_MATCHED_PREFIX() |
void |
setCreated(long created) |
void |
setDescription(String description) |
void |
setEnabled(boolean enabled) |
void |
setName(String name) |
void |
setNotes(String notes) |
void |
setStoreFailures(boolean store_failures) |
void |
setStrictMatch(boolean strict_match) |
void |
setTreeId(int treeId) |
com.stumbleupon.async.Deferred<Boolean> |
storeTree(TSDB tsdb,
boolean overwrite)
Attempts to store the tree definition via a CompareAndSet call.
|
String |
toString() |
static byte[] |
TREE_FAMILY() |
static int |
TREE_ID_WIDTH() |
public Tree()
public Tree(int tree_id)
tree_id
- ID of this treepublic Tree(Tree original)
original
- The original object to copy fromPatternSyntaxException
- if one of the rule's regex is invalidpublic String toString()
public boolean copyChanges(Tree tree, boolean overwrite)
tree
- The tree to copy fromoverwrite
- Whether or not to copy all values from the incoming treeIllegalArgumentException
- if the incoming tree was invalidpublic void addRule(TreeRule rule)
rule
- The rule to addIllegalArgumentException
- if the incoming rule was invalidpublic void addCollision(String tsuid, String existing_tsuid)
tsuid
- TSUID to add to the setIllegalArgumentException
- if the tsuid was invalidpublic void addNotMatched(String tsuid, String message)
tsuid
- TSUID to add to the setIllegalArgumentException
- if the tsuid was invalidpublic com.stumbleupon.async.Deferred<Boolean> storeTree(TSDB tsdb, boolean overwrite)
tsdb
- The TSDB to use for accessoverwrite
- Whether or not tree data should be overwrittenIllegalArgumentException
- if the tree ID is missing or invalidorg.hbase.async.HBaseException
- if a storage exception occurredpublic TreeRule getRule(int level, int order)
level
- The level where the rule residesorder
- The order in the level where the rule residespublic com.stumbleupon.async.Deferred<Integer> createNewTree(TSDB tsdb)
TREE_ID_WIDTH
, we will throw an exception.tsdb
- The TSDB to use for storage accesspublic static com.stumbleupon.async.Deferred<Tree> fetchTree(TSDB tsdb, int tree_id)
tsdb
- The TSDB to use for accesstree_id
- The Tree to fetchIllegalArgumentException
- if the tree ID was invalidorg.hbase.async.HBaseException
- if a storage exception occurredJSONException
- if the object could not be deserializedpublic static com.stumbleupon.async.Deferred<List<Tree>> fetchAllTrees(TSDB tsdb)
tsdb
- The TSDB to use for storagepublic static com.stumbleupon.async.Deferred<Map<String,String>> fetchCollisions(TSDB tsdb, int tree_id, List<String> tsuids)
tsdb
- TSDB to use for storage accesstree_id
- ID of the tree to fetch collisions fortsuids
- An optional list of TSUIDs to fetch collisions for. This may
be empty or null, in which case all collisions for the tree will be
returned.org.hbase.async.HBaseException
- if there was an issueIllegalArgumentException
- if the tree ID was invalidpublic static com.stumbleupon.async.Deferred<Map<String,String>> fetchNotMatched(TSDB tsdb, int tree_id, List<String> tsuids)
tsdb
- TSDB to use for storage accesstree_id
- ID of the tree to fetch non matches fortsuids
- An optional list of TSUIDs to fetch non-matches for. This may
be empty or null, in which case all non-matches for the tree will be
returned.org.hbase.async.HBaseException
- if there was an issueIllegalArgumentException
- if the tree ID was invalidpublic static com.stumbleupon.async.Deferred<Boolean> deleteTree(TSDB tsdb, int tree_id, boolean delete_definition)
tsdb
- The TSDB to use for storage accesstree_id
- ID of the tree to deletedelete_definition
- Whether or not the tree definition and rule set
should be deleted as wellorg.hbase.async.HBaseException
- if there was an issueIllegalArgumentException
- if the tree ID was invalidpublic static byte[] idToBytes(int tree_id)
TREE_ID_WIDTH
in sizetree_id
- The tree ID to convertIllegalArgumentException
- if the Tree ID is invalidpublic static int bytesToId(byte[] row_key)
TREE_ID_WIDTH
bytes.row_key
- The row key or tree ID as a byte arrayIllegalArgumentException
- if the byte array is less than
TREE_ID_WIDTH
longpublic static byte[] COLLISION_PREFIX()
public static byte[] NOT_MATCHED_PREFIX()
public static byte[] TREE_FAMILY()
public com.stumbleupon.async.Deferred<Boolean> flushCollisions(TSDB tsdb)
collisions
maptsdb
- The TSDB to use for storage accessorg.hbase.async.HBaseException
- if there was an issuepublic com.stumbleupon.async.Deferred<Boolean> flushNotMatched(TSDB tsdb)
not_matched
maptsdb
- The TSDB to use for storage accessorg.hbase.async.HBaseException
- if there was an issuepublic static int TREE_ID_WIDTH()
public int getTreeId()
public String getName()
public String getDescription()
public String getNotes()
public boolean getStrictMatch()
public boolean getEnabled()
public boolean getStoreFailures()
public Map<String,String> getNotMatched()
public Map<String,String> getCollisions()
public long getCreated()
public void setName(String name)
name
- A descriptive name for the treepublic void setDescription(String description)
description
- A brief description of the treepublic void setNotes(String notes)
notes
- Optional notes about the treepublic void setStrictMatch(boolean strict_match)
strict_match
- Whether or not a TSUID must match all rules in the
tree to be includedpublic void setEnabled(boolean enabled)
enabled
- Whether or not this tree should process TSMeta objectspublic void setStoreFailures(boolean store_failures)
store_failures
- Whether or not to store not matched or collisionspublic void setTreeId(int treeId)
treeId
- ID of the tree, users cannot modify thispublic void setCreated(long created)
created
- The time when this tree was created,
Unix epoch in seconds