/** @return True if the CAS was successful, false if not */ @Override public Deferred<Boolean> call(final TreeRule fetched_rule) { TreeRule stored_rule = fetched_rule; final byte[] original_rule = stored_rule == null ? new byte[0] : JSON.serializeToBytes(stored_rule); if (stored_rule == null) { stored_rule = local_rule; } else { if (!stored_rule.copyChanges(local_rule, overwrite)) { LOG.debug(this + " does not have changes, skipping sync to storage"); throw new IllegalStateException("No changes detected in the rule"); } } // reset the local change map so we don't keep writing on subsequent // requests initializeChangedMap(); // validate before storing stored_rule.validateRule(); final PutRequest put = new PutRequest( tsdb.treeTable(), Tree.idToBytes(tree_id), Tree.TREE_FAMILY(), getQualifier(level, order), JSON.serializeToBytes(stored_rule)); return tsdb.getClient().compareAndSet(put, original_rule); }
/** * Parses a rule from the given column. Used by the Tree class when scanning a row for rules. * * @param column The column to parse * @return A valid TreeRule object if parsed successfully * @throws IllegalArgumentException if the column was empty * @throws JSONException if the object could not be serialized */ public static TreeRule parseFromStorage(final KeyValue column) { if (column.value() == null) { throw new IllegalArgumentException("Tree rule column value was null"); } final TreeRule rule = JSON.parseToObject(column.value(), TreeRule.class); rule.initializeChangedMap(); return rule; }