Package net.opentsdb.meta

Examples of net.opentsdb.meta.Annotation


        KeyValue kv = row.get(0);
        final byte[] qual = kv.qualifier();
        if (qual.length % 2 != 0 || qual.length == 0) {
          // This could be a row with only an annotation in it
          if ((qual[0] | Annotation.PREFIX()) == Annotation.PREFIX()) {
            final Annotation note = JSON.parseToObject(kv.value(),
                Annotation.class);
            annotations.add(note);
          }
          return null;
        }
        final byte[] val = kv.value();
        if (qual.length == 2 && Internal.floatingPointValueToFix(qual[1], val)) {
          // Fix up old, incorrectly encoded floating point value.
          final byte[] newval = Internal.fixFloatingPointValue(qual[1], val);
          final byte[] newqual = new byte[] { qual[0],
            Internal.fixQualifierFlags(qual[1], newval.length) };
          kv = new KeyValue(kv.key(), kv.family(), newqual, newval);
        }
        compacted[0] = kv;
      }
      return null;
    }

    // We know we have at least 2 cells.  We need to go through all the cells
    // to determine what kind of compaction we're going to do.  If each cell
    // contains a single individual data point, then we can do a trivial
    // compaction.  Otherwise, we have a partially compacted row, and the
    // logic required to compact it is more complex.
    boolean write = true// Do we need to write a compacted cell?
    final KeyValue compact;
    {
      boolean trivial = true// Are we doing a trivial compaction?
      boolean ms_in_row = false;
      boolean s_in_row = false;
      int qual_len = 0// Pre-compute the size of the qualifier we'll need.
      int val_len = 1;   // Reserve an extra byte for meta-data.
      KeyValue longest = row.get(0)// KV with the longest qualifier.
      int longest_idx = 0;            // Index of `longest'.
      int nkvs = row.size();
      for (int i = 0; i < nkvs; i++) {
        final KeyValue kv = row.get(i);
        final byte[] qual = kv.qualifier();
        // If the qualifier length isn't 2, this row might have already
        // been compacted, potentially partially, so we need to merge the
        // partially compacted set of cells, with the rest.
        final int len = qual.length;
        if (len != 2 && len != 4) {
          // Datapoints and compacted columns should have qualifiers with an
          // even number of bytes. If we find one with an odd number, or an
          // empty qualifier (which is possible), we need to remove it from the
          // compaction queue.
          if (len % 2 != 0 || len == 0) {
            // if the qualifier is 3 bytes and starts with the Annotation prefix,
            // parse it out.
            if ((qual[0] | Annotation.PREFIX()) == Annotation.PREFIX()) {
              final Annotation note = JSON.parseToObject(kv.value(),
                  Annotation.class);
              annotations.add(note);
            }
           
            row.remove(i)// This is O(n) but should happen *very* rarely.
 
View Full Code Here


   * @param query The query to parse and respond to
   */
  public void execute(final TSDB tsdb, HttpQuery query) throws IOException {
    final HttpMethod method = query.getAPIMethod();
   
    final Annotation note;
    if (query.hasContent()) {
      note = query.serializer().parseAnnotationV1();
    } else {
      note = parseQS(query);
    }
   
    // GET
    if (method == HttpMethod.GET) {
      try {
        final Annotation stored_annotation =
          Annotation.getAnnotation(tsdb, note.getTSUID(), note.getStartTime())
            .joinUninterruptibly();
        if (stored_annotation == null) {
          throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
              "Unable to locate annotation in storage");
        }
        query.sendReply(query.serializer().formatAnnotationV1(stored_annotation));
      } catch (BadRequestException e) {
        throw e;
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    // POST
    } else if (method == HttpMethod.POST || method == HttpMethod.PUT) {
     
      /**
       * 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<Annotation>, Boolean> {
       
        @Override
        public Deferred<Annotation> call(Boolean success) throws Exception {
          if (!success) {
            throw new BadRequestException(
                HttpResponseStatus.INTERNAL_SERVER_ERROR,
                "Failed to save the Annotation to storage",
                "This may be caused by another process modifying storage data");
          }
         
          return Annotation.getAnnotation(tsdb, note.getTSUID(),
              note.getStartTime());
        }
       
      }
     
      try {
        final Deferred<Annotation> process_meta = note.syncToStorage(tsdb,
            method == HttpMethod.PUT).addCallbackDeferring(new SyncCB());
        final Annotation updated_meta = process_meta.joinUninterruptibly();
        tsdb.indexAnnotation(note);
        query.sendReply(query.serializer().formatAnnotationV1(updated_meta));
      } catch (IllegalStateException e) {
        query.sendStatusOnly(HttpResponseStatus.NOT_MODIFIED);
      } catch (IllegalArgumentException e) {
View Full Code Here

   * @param query The query to parse
   * @return An annotation object if parsing was successful
   * @throws IllegalArgumentException - if the request was malformed
   */
  private Annotation parseQS(final HttpQuery query) {
    final Annotation note = new Annotation();
   
    final String tsuid = query.getQueryStringParam("tsuid");
    if (tsuid != null) {
      note.setTSUID(tsuid);
    }
   
    final String start = query.getQueryStringParam("start_time");
    final Long start_time = DateTime.parseDateTimeString(start, "");
    if (start_time < 1) {
      throw new BadRequestException("Missing start time");
    }
    // TODO - fix for ms support in the future
    note.setStartTime(start_time / 1000);
   
    final String end = query.getQueryStringParam("end_time");
    final Long end_time = DateTime.parseDateTimeString(end, "");
    // TODO - fix for ms support in the future
    note.setEndTime(end_time / 1000);
   
    final String description = query.getQueryStringParam("description");
    if (description != null) {
      note.setDescription(description);
    }
   
    final String notes = query.getQueryStringParam("notes");
    if (notes != null) {
      note.setNotes(notes);
    }
   
    return note;
  }
View Full Code Here

        null, null, (short)0x7));
  }
 
  @Test
  public void publishAnnotation() throws Exception {
    Annotation ann = new Annotation();
    HashMap<String, String> customMap = new HashMap<String, String>(1);
    customMap.put("test-custom-key", "test-custom-value");
    ann.setCustom(customMap);
    ann.setDescription("A test annotation");
    ann.setNotes("Test annotation notes");
    ann.setStartTime(System.currentTimeMillis());   
    assertNotNull(rt_publisher.publishAnnotation(ann));
  }
View Full Code Here

              name_field.set(uid2, "host");
              results.add(uid2);
              break;
             
            case ANNOTATION:
              final Annotation note = new Annotation();
              note.setStartTime(1356998400);
              note.setEndTime(1356998460);
              note.setDescription("Something went pear shaped");
              note.setTSUID("000001000001000001");
              results.add(note);
              break;
          }
         
          search_query.setResults(results);
View Full Code Here

 
  @Test
  public void runWithAnnotation() throws Exception {
    storeLongTimeSeriesSeconds(true, false);;
   
    final Annotation note = new Annotation();
    note.setTSUID("000001000001000001");
    note.setStartTime(1356998490);
    note.setDescription("Hello World!");
    note.syncToStorage(tsdb, false).joinUninterruptibly();
   
    HashMap<String, String> tags = new HashMap<String, String>(1);
    tags.put("host", "web01");
    query.setStartTime(1356998400);
    query.setEndTime(1357041600);
View Full Code Here

 
  @Test
  public void runWithAnnotationPostCompact() throws Exception {
    storeLongTimeSeriesSeconds(true, false);;
   
    final Annotation note = new Annotation();
    note.setTSUID("000001000001000001");
    note.setStartTime(1356998490);
    note.setDescription("Hello World!");
    note.syncToStorage(tsdb, false).joinUninterruptibly();
   
    final Field compact = Config.class.getDeclaredField("enable_compactions");
    compact.setAccessible(true);
    compact.set(config, true);
   
View Full Code Here

    storeLongTimeSeriesSeconds(true, false);;
   
    // verifies that we can pickup an annotation stored all bye it's lonesome
    // in a row without any data
    storage.flushRow(MockBase.stringToBytes("00000150E23510000001000001"));
    final Annotation note = new Annotation();
    note.setTSUID("000001000001000001");
    note.setStartTime(1357002090);
    note.setDescription("Hello World!");
    note.syncToStorage(tsdb, false).joinUninterruptibly();
   
    HashMap<String, String> tags = new HashMap<String, String>(1);
    tags.put("host", "web01");
    query.setStartTime(1356998400);
    query.setEndTime(1357041600);
View Full Code Here

  private void writeData() throws Exception {
    HashMap<String, String> tags = new HashMap<String, String>(1);
    tags.put("host", "web01");
    long timestamp = 1356998400;
   
    Annotation annotation = new Annotation();
    annotation.setStartTime(timestamp);
    annotation.setTSUID("000001000001000001");
    annotation.setDescription("Annotation on seconds");
    annotation.syncToStorage(tsdb, false).joinUninterruptibly();
   
    tsdb.addPoint("sys.cpu.user", timestamp++, 42, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp++, 257, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp++, 65537, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp++, 4294967296L, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp++, 42.5F, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp++, 42.5123459999F, tags)
      .joinUninterruptibly();
   
    timestamp = 1357002000000L;
   
    annotation = new Annotation();
    annotation.setStartTime(timestamp);
    annotation.setTSUID("000001000001000001");
    annotation.setDescription("Annotation on milliseconds");
    annotation.syncToStorage(tsdb, false).joinUninterruptibly();
   
    tsdb.addPoint("sys.cpu.user", timestamp, 42, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp += 1000, 257, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp += 1000, 65537, tags).joinUninterruptibly();
    tsdb.addPoint("sys.cpu.user", timestamp += 1000, 4294967296L, tags).joinUninterruptibly();
View Full Code Here

    final byte[] val2 = new byte[] { 0, 0, 0, 0, 0, 0, 0,5 };

    storage.addColumn(ROW, qual1, val1);
    storage.addColumn(ROW, qual2, val2);

    final Annotation note = new Annotation();
    note.setTSUID(MockBase.bytesToString(ROW));
    note.setDescription("woot");
    note.setStartTime(1356998460);
    note.syncToStorage(tsdb, true).joinUninterruptibly();
    int errors = (Integer)fsck.invoke(null, tsdb, client,
        "tsdb".getBytes(MockBase.ASCII()), false, new String[] {
        "1356998400", "1357002000", "sum", "sys.cpu.user" });
    assertEquals(0, errors);
  }
View Full Code Here

TOP

Related Classes of net.opentsdb.meta.Annotation

Copyright © 2018 www.massapicom. 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.