Examples of UIDMeta


Examples of net.opentsdb.meta.UIDMeta

      }

      cacheMapping(name, row);
     
      if (tsdb != null && tsdb.getConfig().enable_realtime_uid()) {
        final UIDMeta meta = new UIDMeta(type, row, name);
        meta.storeNew(tsdb);
        LOG.info("Wrote UIDMeta for: " + name);
        tsdb.indexUIDMeta(meta);
      }
     
      synchronized (pending_assignments) {
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

      throw new IllegalStateException(
        "Timeseries meta data was missing tags");
    }
   
    // first, find the tagk UIDMeta we're matching against
    UIDMeta tagk = null;
    for (UIDMeta tag: meta.getTags()) {
      if (tag.getType() == UniqueIdType.TAGK &&
          tag.getName().equals(rule.getField())) {
        tagk = tag;
        break;
      }
    }
   
    if (tagk == null) {
      testMessage("No match on tagk [" + rule.getField() + "] for rule: " +
          rule);
      return;
    }
   
    // now scan the custom tags for a matching tag name and it's value
    testMessage("Matched tagk [" + rule.getField() + "] for rule: " +
        rule);
    final Map<String, String> custom = tagk.getCustom();
    if (custom != null && custom.containsKey(rule.getCustomField())) {
      if (custom.get(rule.getCustomField()) == null) {
        throw new IllegalStateException(
            "Value for custom tagk field [" + rule.getCustomField() +
            "] was null");
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

      throw new IllegalStateException(
        "Timeseries meta data was missing tags");
    }
   
    // first, find the tagv UIDMeta we're matching against
    UIDMeta tagv = null;
    for (UIDMeta tag: meta.getTags()) {
      if (tag.getType() == UniqueIdType.TAGV &&
          tag.getName().equals(rule.getField())) {
        tagv = tag;
        break;
      }
    }
   
    if (tagv == null) {
      testMessage("No match on tagv [" + rule.getField() + "] for rule: " +
          rule);
      return;
    }
   
    // now scan the custom tags for a matching tag name and it's value
    testMessage("Matched tagv [" + rule.getField() + "] for rule: " +
        rule);
    final Map<String, String> custom = tagv.getCustom();
    if (custom != null && custom.containsKey(rule.getCustomField())) {
      if (custom.get(rule.getCustomField()) == null) {
        throw new IllegalStateException(
            "Value for custom tagv field [" + rule.getCustomField() +
            "] was null");
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

       */
      final class UidNameCB implements Callback<Deferred<Boolean>, String> {

        @Override
        public Deferred<Boolean> call(final String name) throws Exception {
          UIDMeta new_meta = new UIDMeta(type, uid, name);
          new_meta.setCreated(timestamp);
          tsdb.indexUIDMeta(new_meta);
          LOG.info("Replacing corrupt UID [" + UniqueId.uidToString(uid) +
            "] of type [" + type + "]");
         
          return new_meta.syncToStorage(tsdb, true);
        }
       
      }
     
      @Override
      public Deferred<Boolean> call(final UIDMeta meta) throws Exception {

        // we only want to update the time if it was outside of an hour
        // otherwise it's probably an accurate timestamp
        if (meta.getCreated() > (timestamp + 3600) ||
            meta.getCreated() == 0) {
          LOG.info("Updating UID [" + UniqueId.uidToString(uid) +
              "] of type [" + type + "]");
          meta.setCreated(timestamp);
         
          // if the UIDMeta object was missing any of these fields, we'll
          // consider it corrupt and replace it with a new object
          if (meta.getUID() == null || meta.getUID().isEmpty() ||
              meta.getType() == null) {
            return tsdb.getUidName(type, uid)
              .addCallbackDeferring(new UidNameCB());
          } else {
            // the meta was good, just needed a timestamp update so sync to
            // search and storage
            tsdb.indexUIDMeta(meta);
            LOG.info("Syncing valid UID [" + UniqueId.uidToString(uid) +
              "] of type [" + type + "]");
            return meta.syncToStorage(tsdb, false);
          }
        } else {
          LOG.debug("UID [" + UniqueId.uidToString(uid) +
              "] of type [" + type + "] is up to date in storage");
          return Deferred.fromResult(true);
        }
      }
     
    }
   
    /**
     * Called to handle a previously unprocessed TSMeta object. This callback
     * will update the "created" timestamp, create a new TSMeta object if
     * missing, and update search plugins.
     */
    final class TSMetaCB implements Callback<Deferred<Boolean>, TSMeta> {
     
      private final String tsuid_string;
      private final byte[] tsuid;
      private final long timestamp;
     
      /**
       * Default constructor
       * @param tsuid ID of the timeseries
       * @param timestamp The timestamp when the first data point was recorded
       */
      public TSMetaCB(final byte[] tsuid, final long timestamp) {
        this.tsuid = tsuid;
        tsuid_string = UniqueId.uidToString(tsuid);
        this.timestamp = timestamp;
      }

      @Override
      public Deferred<Boolean> call(final TSMeta meta) throws Exception {
       
        // if we couldn't find a TSMeta in storage, then we need to generate a
        // new one
        if (meta == null) {
         
          /**
           * Called after successfully creating a TSMeta counter and object,
           * used to convert the deferred long to a boolean so it can be
           * combined with other calls for waiting.
           */
          final class CreatedCB implements Callback<Deferred<Boolean>, Long> {

            @Override
            public Deferred<Boolean> call(Long value) throws Exception {
              LOG.info("Created counter and meta for timeseries [" +
                  tsuid_string + "]");
              return Deferred.fromResult(true);
            }
           
          }
         
          /**
           * Called after checking to see if the counter exists and is used
           * to determine if we should create a new counter AND meta or just a
           * new meta
           */
          final class CounterCB implements Callback<Deferred<Boolean>, Boolean> {
           
            @Override
            public Deferred<Boolean> call(final Boolean exists) throws Exception {
              if (!exists) {
                // note that the increment call will create the meta object
                // and send it to the search plugin so we don't have to do that
                // here or in the local callback
                return TSMeta.incrementAndGetCounter(tsdb, tsuid)
                  .addCallbackDeferring(new CreatedCB());
              } else {
                TSMeta new_meta = new TSMeta(tsuid, timestamp);
                tsdb.indexTSMeta(new_meta);
                LOG.info("Counter exists but meta was null, creating meta data for timeseries [" +
                    tsuid_string + "]");
                return new_meta.storeNew(tsdb);   
              }
            }
          }
         
          // Take care of situations where the counter is created but the
          // meta data is not. May happen if the TSD crashes or is killed
          // improperly before the meta is flushed to storage.
          return TSMeta.counterExistsInStorage(tsdb, tsuid)
            .addCallbackDeferring(new CounterCB());
        }

        // verify the tsuid is good, it's possible for this to become
        // corrupted
        if (meta.getTSUID() == null ||
            meta.getTSUID().isEmpty()) {
          LOG.warn("Replacing corrupt meta data for timeseries [" +
              tsuid_string + "]");
          TSMeta new_meta = new TSMeta(tsuid, timestamp);
          tsdb.indexTSMeta(new_meta);
          return new_meta.storeNew(tsdb);
        } else {
          // we only want to update the time if it was outside of an
          // hour otherwise it's probably an accurate timestamp
          if (meta.getCreated() > (timestamp + 3600) ||
              meta.getCreated() == 0) {
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

       */
      final class UidNameCB implements Callback<Deferred<Boolean>, String> {

        @Override
        public Deferred<Boolean> call(final String name) throws Exception {
          UIDMeta new_meta = new UIDMeta(type, uid, name);
          new_meta.setCreated(timestamp);
          tsdb.indexUIDMeta(new_meta);
          LOG.info("Replacing corrupt UID [" + UniqueId.uidToString(uid) +
            "] of type [" + type + "]");
         
          return new_meta.syncToStorage(tsdb, true);
        }
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

            case TSMETA:
              final TSMeta meta = new TSMeta("000001000001000001");
              meta.setCreated(1356998400);
              meta.setDescription("System CPU metric");
             
              UIDMeta uid = new UIDMeta(UniqueIdType.METRIC, "000001");
              final Field uid_name = UIDMeta.class.getDeclaredField("name");
              uid_name.setAccessible(true);
              uid_name.set(uid, "sys.cpu.0");
             
              final Field metric = TSMeta.class.getDeclaredField("metric");
              metric.setAccessible(true);
              metric.set(meta, uid);
             
              final ArrayList<UIDMeta> tags = new ArrayList<UIDMeta>(2);
              uid = new UIDMeta(UniqueIdType.TAGK, "000001");
              uid_name.set(uid, "host");
              tags.add(uid);
              uid = new UIDMeta(UniqueIdType.TAGV, "000001");
              uid_name.set(uid, "web01");
              tags.add(uid);
             
              final Field tags_field = TSMeta.class.getDeclaredField("tags");
              tags_field.setAccessible(true);
              tags_field.set(meta, tags);
              results.add(meta);
              break;
             
            case TSMETA_SUMMARY:
              final HashMap<String, Object> ts = new HashMap<String, Object>(1);
              ts.put("metric", "sys.cpu.0");
              final HashMap<String, String> tag_map =
                new HashMap<String, String>(2);
              tag_map.put("host", "web01");
              tag_map.put("owner", "ops");
              ts.put("tags", tag_map);
              results.add(ts);
              break;
             
            case TSUIDS:
              results.add("000001000001000001");
              results.add("000002000002000002");
              break;
             
            case UIDMETA:
              UIDMeta uid2 = new UIDMeta(UniqueIdType.METRIC, "000001");
              final Field name_field = UIDMeta.class.getDeclaredField("name");
              name_field.setAccessible(true);
              name_field.set(uid2, "sys.cpu.0");
              results.add(uid2);
             
              uid2 = new UIDMeta(UniqueIdType.TAGK, "000001");
              name_field.set(uid2, "host");
              results.add(uid2);
              break;
             
            case ANNOTATION:
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

    final TSMeta meta = new TSMeta("000001000001000001000002000002");
    storage.addColumn(UniqueId.stringToUid("000001000001000001000002000002"),
        NAME_FAMILY, "ts_meta".getBytes(MockBase.ASCII()),
        (byte[])TSMetagetStorageJSON.invoke(meta));
   
    final UIDMeta metric = new UIDMeta(UniqueIdType.METRIC, new byte[] { 0, 0, 1 },
        "sys.cpu.0");
    storage.addColumn(new byte[] { 0, 0, 1 }, NAME_FAMILY,
        "metric_meta".getBytes(MockBase.ASCII()),
        (byte[])UIDMetagetStorageJSON.invoke(metric));
    final UIDMeta tagk1 = new UIDMeta(UniqueIdType.TAGK, new byte[] { 0, 0, 1 },
        "host");
    storage.addColumn(new byte[] { 0, 0, 1 }, NAME_FAMILY,
        "tagk_meta".getBytes(MockBase.ASCII()),
        (byte[])UIDMetagetStorageJSON.invoke(tagk1));
    final UIDMeta tagv1 = new UIDMeta(UniqueIdType.TAGV, new byte[] { 0, 0, 1 },
        "web-01.lga.mysite.com");
    storage.addColumn(new byte[] { 0, 0, 1 }, NAME_FAMILY,
        "tagv_meta".getBytes(MockBase.ASCII()),
        (byte[])UIDMetagetStorageJSON.invoke(tagv1));
    final UIDMeta tagk2 = new UIDMeta(UniqueIdType.TAGK, new byte[] { 0, 0, 2 },
        "type");
    storage.addColumn(new byte[] { 0, 0, 2 }, NAME_FAMILY,
        "tagk_meta".getBytes(MockBase.ASCII()),
        (byte[])UIDMetagetStorageJSON.invoke(tagk2));
    final UIDMeta tagv2 = new UIDMeta(UniqueIdType.TAGV, new byte[] { 0, 0, 2 },
        "user");
    storage.addColumn(new byte[] { 0, 0, 2 }, NAME_FAMILY,
        "tagv_meta".getBytes(MockBase.ASCII()),
        (byte[])UIDMetagetStorageJSON.invoke(tagv2));
   
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

     
      final String uid = query.getRequiredQueryStringParam("uid");
      final UniqueIdType type = UniqueId.stringToUniqueIdType(
          query.getRequiredQueryStringParam("type"));
      try {
        final UIDMeta meta = UIDMeta.getUIDMeta(tsdb, type, uid)
        .joinUninterruptibly();
        query.sendReply(query.serializer().formatUidMetaV1(meta));
      } catch (NoSuchUniqueId e) {
        throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
            "Could not find the requested UID", e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    // POST
    } else if (method == HttpMethod.POST || method == HttpMethod.PUT) {
     
      final UIDMeta meta;
      if (query.hasContent()) {
        meta = query.serializer().parseUidMetaV1();
      } else {
        meta = this.parseUIDMetaQS(query);
      }
     
      /**
       * Storage callback used to determine if the storage call was successful
       * or not. Also returns the updated object from storage.
       */
      class SyncCB implements Callback<Deferred<UIDMeta>, Boolean> {
       
        @Override
        public Deferred<UIDMeta> call(Boolean success) throws Exception {
          if (!success) {
            throw new BadRequestException(
                HttpResponseStatus.INTERNAL_SERVER_ERROR,
                "Failed to save the UIDMeta to storage",
                "This may be caused by another process modifying storage data");
          }
         
          return UIDMeta.getUIDMeta(tsdb, meta.getType(), meta.getUID());
        }
       
      }
     
      try {
        final Deferred<UIDMeta> process_meta = meta.syncToStorage(tsdb,
            method == HttpMethod.PUT).addCallbackDeferring(new SyncCB());
        final UIDMeta updated_meta = process_meta.joinUninterruptibly();
        tsdb.indexUIDMeta(updated_meta);
        query.sendReply(query.serializer().formatUidMetaV1(updated_meta));
      } catch (IllegalStateException e) {
        query.sendStatusOnly(HttpResponseStatus.NOT_MODIFIED);
      } catch (IllegalArgumentException e) {
        throw new BadRequestException(e);
      } catch (NoSuchUniqueId e) {
        throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
            "Could not find the requested UID", e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    // DELETE   
    } else if (method == HttpMethod.DELETE) {
     
      final UIDMeta meta;
      if (query.hasContent()) {
        meta = query.serializer().parseUidMetaV1();
      } else {
        meta = this.parseUIDMetaQS(query);
      }
      try {       
        meta.delete(tsdb).joinUninterruptibly();
        tsdb.deleteUIDMeta(meta);
      } catch (IllegalArgumentException e) {
        throw new BadRequestException("Unable to delete UIDMeta information", e);
      } catch (NoSuchUniqueId e) {
        throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

   * be parsed
   */
  private UIDMeta parseUIDMetaQS(final HttpQuery query) {
    final String uid = query.getRequiredQueryStringParam("uid");
    final String type = query.getRequiredQueryStringParam("type");
    final UIDMeta meta = new UIDMeta(UniqueId.stringToUniqueIdType(type), uid);
    final String display_name = query.getQueryStringParam("display_name");
    if (display_name != null) {
      meta.setDisplayName(display_name);
    }
   
    final String description = query.getQueryStringParam("description");
    if (description != null) {
      meta.setDescription(description);
    }
   
    final String notes = query.getQueryStringParam("notes");
    if (notes != null) {
      meta.setNotes(notes);
    }
   
    return meta;
  }
View Full Code Here

Examples of net.opentsdb.meta.UIDMeta

    when(tsdb.assignUid("tagv", "myserver")).thenThrow(
        new IllegalArgumentException("Name already exists with UID: 000002"));
    when(tsdb.assignUid("tagv", "foo")).thenReturn(new byte[] { 0, 0, 3 });
   
    // setup UIDMeta objects for testing
    UIDMeta metric = new UIDMeta(UniqueIdType.METRIC, new byte[] {0, 0, 1},
        "sys.cpu.0");
    metric.setDisplayName("System CPU");
    UIDMeta tagk = new UIDMeta(UniqueIdType.TAGK, new byte[] {0, 0, 1},
        "host");
    tagk.setDisplayName("Server Name");
    UIDMeta tagv = new UIDMeta(UniqueIdType.TAGV, new byte[] {0, 0, 1},
        "web01");
    tagv.setDisplayName("Web Server 1");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.