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(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(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(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(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(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(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(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(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(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(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(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(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(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(branch.compileBranchId(), Tree.TREE_FAMILY(),
"branch".getBytes(MockBase.ASCII()),
(byte[])branchToStorageJson.invoke(branch));
Leaf leaf = new Leaf("user", "000001000001000001");
qualifier = leaf.columnQualifier();
storage.addColumn(branch.compileBranchId(), Tree.TREE_FAMILY(),
qualifier, (byte[])LeaftoStorageJson.invoke(leaf));
leaf = new Leaf("nice", "000002000002000002");
qualifier = leaf.columnQualifier();
storage.addColumn(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(branch.compileBranchId(), Tree.TREE_FAMILY(),
"branch".getBytes(MockBase.ASCII()),
(byte[])branchToStorageJson.invoke(branch));
leaf = new Leaf("Asus", "000003000003000003");
qualifier = leaf.columnQualifier();
storage.addColumn(branch.compileBranchId(), Tree.TREE_FAMILY(),
qualifier, (byte[])LeaftoStorageJson.invoke(leaf));
}