Search in sources :

Example 6 with UIDMeta

use of net.opentsdb.meta.UIDMeta in project opentsdb by OpenTSDB.

the class TestTreeRpc method setupTSMeta.

/**
   * Sets up a TSMeta object and associated UIDMeta objects in storage for 
   * testing the "test" call. These are necessary as the TSMeta is loaded when
   * parsed through the tree.
   */
private void setupTSMeta() throws Exception {
    final byte[] meta_table = "tsdb-meta".getBytes();
    final byte[] uid_table = "tsdb-uid".getBytes();
    final List<byte[]> families = new ArrayList<byte[]>(1);
    families.add(TSMeta.FAMILY);
    storage.addTable(meta_table, families);
    final TSMeta meta = new TSMeta("000001000001000001000002000002");
    storage.addColumn(meta_table, 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(uid_table, 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(uid_table, 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(uid_table, 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(uid_table, 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(uid_table, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagv_meta".getBytes(MockBase.ASCII()), (byte[]) UIDMetagetStorageJSON.invoke(tagv2));
    storage.addColumn(uid_table, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagk".getBytes(MockBase.ASCII()), "type".getBytes(MockBase.ASCII()));
    storage.addColumn(uid_table, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagv".getBytes(MockBase.ASCII()), "user".getBytes(MockBase.ASCII()));
}
Also used : UIDMeta(net.opentsdb.meta.UIDMeta) ArrayList(java.util.ArrayList) TSMeta(net.opentsdb.meta.TSMeta)

Example 7 with UIDMeta

use of net.opentsdb.meta.UIDMeta in project opentsdb by OpenTSDB.

the class TreeBuilder method parseTagkRule.

/**
   * Processes the tag value paired with a tag name. Routes to the 
   * {@link #processParsedValue} method after processing if successful
   * @throws IllegalStateException if the tag UIDMetas have not be set
   */
private void parseTagkRule() {
    final List<UIDMeta> tags = meta.getTags();
    if (tags == null || tags.isEmpty()) {
        throw new IllegalStateException("Tags for the timeseries meta were null");
    }
    String tag_name = "";
    boolean found = false;
    // we're screwed
    for (UIDMeta uidmeta : tags) {
        if (uidmeta.getType() == UniqueIdType.TAGK && uidmeta.getName().equals(rule.getField())) {
            found = true;
        } else if (uidmeta.getType() == UniqueIdType.TAGV && found) {
            tag_name = uidmeta.getName();
            break;
        }
    }
    // if we didn't find a match, return
    if (!found || tag_name.isEmpty()) {
        testMessage("No match on tagk [" + rule.getField() + "] for rule: " + rule);
        return;
    }
    // matched!
    testMessage("Matched tagk [" + rule.getField() + "] for rule: " + rule);
    processParsedValue(tag_name);
}
Also used : UIDMeta(net.opentsdb.meta.UIDMeta)

Example 8 with UIDMeta

use of net.opentsdb.meta.UIDMeta in project opentsdb by OpenTSDB.

the class TreeBuilder method parseTagkCustomRule.

/**
   * Processes the custom tag value paired with a custom tag name. Routes to the 
   * {@link #processParsedValue} method after processing if successful.
   * If the custom tag group is null or empty for the tagk, or the tagk couldn't
   * be found, we just return.
   * @throws IllegalStateException if the tags UIDMeta array has not been set
   */
private void parseTagkCustomRule() {
    if (meta.getTags() == null || meta.getTags().isEmpty()) {
        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");
        }
        processParsedValue(custom.get(rule.getCustomField()));
        testMessage("Matched custom tag [" + rule.getCustomField() + "] for rule: " + rule);
    } else {
        testMessage("No match on custom tag [" + rule.getCustomField() + "] for rule: " + rule);
        return;
    }
}
Also used : UIDMeta(net.opentsdb.meta.UIDMeta)

Example 9 with UIDMeta

use of net.opentsdb.meta.UIDMeta in project opentsdb by OpenTSDB.

the class UniqueIdRpc method handleUIDMeta.

/**
   * Handles CRUD calls to individual UIDMeta data entries
   * @param tsdb The TSDB from the RPC router
   * @param query The query for this request
   */
private void handleUIDMeta(final TSDB tsdb, final HttpQuery query) {
    final HttpMethod method = query.getAPIMethod();
    // GET
    if (method == HttpMethod.GET) {
        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, "Could not find the requested UID", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
    } else {
        throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, "Method not allowed", "The HTTP method [" + method.getName() + "] is not permitted for this endpoint");
    }
}
Also used : Deferred(com.stumbleupon.async.Deferred) UniqueIdType(net.opentsdb.uid.UniqueId.UniqueIdType) IOException(java.io.IOException) UIDMeta(net.opentsdb.meta.UIDMeta) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod)

Example 10 with UIDMeta

use of net.opentsdb.meta.UIDMeta in project opentsdb by OpenTSDB.

the class TestTreeBuilder method processTimeseriesMetaNullMetaOddNumTags.

@Test
public void processTimeseriesMetaNullMetaOddNumTags() throws Exception {
    ArrayList<UIDMeta> tags = new ArrayList<UIDMeta>(4);
    tags.add(tagk1);
    //tags.add(tagv1); <-- whoops. This will process through but missing host
    tags.add(tagk2);
    tags.add(tagv2);
    Field tags_field = TSMeta.class.getDeclaredField("tags");
    tags_field.setAccessible(true);
    tags_field.set(meta, tags);
    tags_field.setAccessible(false);
    treebuilder.processTimeseriesMeta(meta, false).joinUninterruptibly();
    assertEquals(5, storage.numRows(TREE_TABLE));
    assertEquals(2, storage.numColumns(TREE_TABLE, Branch.stringToId("00010036EBCB0001BECD000181A800000030")));
}
Also used : Field(java.lang.reflect.Field) UIDMeta(net.opentsdb.meta.UIDMeta) ArrayList(java.util.ArrayList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UIDMeta (net.opentsdb.meta.UIDMeta)11 ArrayList (java.util.ArrayList)5 Deferred (com.stumbleupon.async.Deferred)3 Field (java.lang.reflect.Field)3 TSMeta (net.opentsdb.meta.TSMeta)3 UniqueIdType (net.opentsdb.uid.UniqueId.UniqueIdType)2 Callback (com.stumbleupon.async.Callback)1 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TSDB (net.opentsdb.core.TSDB)1 Annotation (net.opentsdb.meta.Annotation)1 SearchPlugin (net.opentsdb.search.SearchPlugin)1 SearchQuery (net.opentsdb.search.SearchQuery)1 MockBase (net.opentsdb.storage.MockBase)1 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)1 Config (net.opentsdb.utils.Config)1 KeyValue (org.hbase.async.KeyValue)1