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()));
}
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);
}
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;
}
}
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");
}
}
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")));
}
Aggregations