use of net.opentsdb.tree.TreeRule in project opentsdb by OpenTSDB.
the class TestTreeRule method storeRuleInvalidMissingFieldTagvCustom.
@Test(expected = IllegalArgumentException.class)
public void storeRuleInvalidMissingFieldTagvCustom() throws Exception {
setupStorage();
final TreeRule rule = new TreeRule(1);
rule.setLevel(1);
rule.setOrder(0);
rule.setType(TreeRuleType.TAGV_CUSTOM);
rule.setNotes("Just some notes");
rule.syncToStorage(storage.getTSDB(), false).joinUninterruptibly();
}
use of net.opentsdb.tree.TreeRule in project opentsdb by OpenTSDB.
the class TestTreeRpc method setupStorage.
/**
* Setups objects in MockBase including two trees, rule sets, root branch,
* child branch, leaves and some collisions and no matches. These are used for
* most of the tests so they're all here.
*/
private void setupStorage() throws Exception {
Tree tree = TestTree.buildTestTree();
// store root
TreeMap<Integer, String> root_path = new TreeMap<Integer, String>();
Branch root = new Branch(tree.getTreeId());
root.setDisplayName("ROOT");
root_path.put(0, "ROOT");
root.prependParentPath(root_path);
storage.addColumn(TREE_TABLE, root.compileBranchId(), Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) branchToStorageJson.invoke(root));
// store the first tree
byte[] key = new byte[] { 0, 1 };
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()), (byte[]) TreetoStorageJson.invoke(TestTree.buildTestTree()));
TreeRule rule = new TreeRule(1);
rule.setField("host");
rule.setDescription("Hostname rule");
rule.setType(TreeRuleType.TAGK);
rule.setDescription("Host Name");
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:0:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
rule = new TreeRule(1);
rule.setField("");
rule.setLevel(1);
rule.setNotes("Metric rule");
rule.setType(TreeRuleType.METRIC);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:1:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
root = new Branch(1);
root.setDisplayName("ROOT");
root_path = new TreeMap<Integer, String>();
root_path.put(0, "ROOT");
root.prependParentPath(root_path);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) branchToStorageJson.invoke(root));
// tree 2
key = new byte[] { 0, 2 };
Tree tree2 = new Tree();
tree2.setTreeId(2);
tree2.setName("2nd Tree");
tree2.setDescription("Other Tree");
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()), (byte[]) TreetoStorageJson.invoke(tree2));
rule = new TreeRule(2);
rule.setField("host");
rule.setType(TreeRuleType.TAGK);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:0:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
rule = new TreeRule(2);
rule.setField("");
rule.setLevel(1);
rule.setType(TreeRuleType.METRIC);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:1:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
root = new Branch(2);
root.setDisplayName("ROOT");
root_path = new TreeMap<Integer, String>();
root_path.put(0, "ROOT");
root.prependParentPath(root_path);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) branchToStorageJson.invoke(root));
// sprinkle in some collisions and no matches for fun
// collisions
key = new byte[] { 0, 1, 1 };
String tsuid = "010101";
byte[] qualifier = new byte[Tree.COLLISION_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.COLLISION_PREFIX(), 0, qualifier, 0, Tree.COLLISION_PREFIX().length);
byte[] tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.COLLISION_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "AAAAAA".getBytes(MockBase.ASCII()));
tsuid = "020202";
qualifier = new byte[Tree.COLLISION_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.COLLISION_PREFIX(), 0, qualifier, 0, Tree.COLLISION_PREFIX().length);
tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.COLLISION_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "BBBBBB".getBytes(MockBase.ASCII()));
// not matched
key = new byte[] { 0, 1, 2 };
tsuid = "010101";
qualifier = new byte[Tree.NOT_MATCHED_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.NOT_MATCHED_PREFIX(), 0, qualifier, 0, Tree.NOT_MATCHED_PREFIX().length);
tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.NOT_MATCHED_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "Failed rule 0:0".getBytes(MockBase.ASCII()));
tsuid = "020202";
qualifier = new byte[Tree.NOT_MATCHED_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.NOT_MATCHED_PREFIX(), 0, qualifier, 0, Tree.NOT_MATCHED_PREFIX().length);
tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.NOT_MATCHED_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "Failed rule 1:1".getBytes(MockBase.ASCII()));
// drop some branches in for tree 1
Branch branch = new Branch(1);
TreeMap<Integer, String> path = new TreeMap<Integer, String>();
path.put(0, "ROOT");
path.put(1, "sys");
path.put(2, "cpu");
branch.prependParentPath(path);
branch.setDisplayName("cpu");
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) branchToStorageJson.invoke(branch));
Leaf leaf = new Leaf("user", "000001000001000001");
qualifier = leaf.columnQualifier();
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), qualifier, (byte[]) LeaftoStorageJson.invoke(leaf));
leaf = new Leaf("nice", "000002000002000002");
qualifier = leaf.columnQualifier();
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), qualifier, (byte[]) LeaftoStorageJson.invoke(leaf));
// child branch
branch = new Branch(1);
path.put(3, "mboard");
branch.prependParentPath(path);
branch.setDisplayName("mboard");
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) branchToStorageJson.invoke(branch));
leaf = new Leaf("Asus", "000003000003000003");
qualifier = leaf.columnQualifier();
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), qualifier, (byte[]) LeaftoStorageJson.invoke(leaf));
}
Aggregations