Example #1
0
      /** @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);
      }
Example #2
0
  /**
   * 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;
  }
Example #3
0
 @Test
 public void deserialize() throws Exception {
   String json =
       "{\"tsuid\":\"ABCD\",\""
           + "description\":\"Description\",\"notes\":\"Notes\",\"created\":1328140800,"
           + "\"custom\":null,\"units\":\"\",\"retention\":42,\"max\":1.0,\"min\":"
           + "\"NaN\",\"displayName\":\"Display\",\"dataType\":\"Data\",\"lastReceived"
           + "\":1328140801,\"unknownkey\":null}";
   TSMeta tsmeta = JSON.parseToObject(json, TSMeta.class);
   assertNotNull(tsmeta);
   assertEquals("ABCD", tsmeta.getTSUID());
   assertEquals("Notes", tsmeta.getNotes());
   assertEquals(42, tsmeta.getRetention());
 }
Example #4
0
 @Test
 public void serialize() throws Exception {
   final String json = JSON.serializeToString(meta);
   assertNotNull(json);
   assertTrue(json.contains("\"created\":0"));
 }