Search in sources :

Example 1 with UniqueId

use of net.opentsdb.uid.UniqueId in project opentsdb by OpenTSDB.

the class UidManager method rename.

/**
   * Implements the {@code rename} subcommand.
   * @param client The HBase client to use.
   * @param table The name of the HBase table to use.
   * @param idwidth Number of bytes on which the UIDs should be.
   * @param args Command line arguments ({@code assign name [names]}).
   * @return The exit status of the command (0 means success).
   */
private static int rename(final HBaseClient client, final byte[] table, final short idwidth, final String[] args) {
    final String kind = args[1];
    final String oldname = args[2];
    final String newname = args[3];
    final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
    try {
        uid.rename(oldname, newname);
    } catch (HBaseException e) {
        LOG.error("error while processing renaming " + oldname + " to " + newname, e);
        return 3;
    } catch (NoSuchUniqueName e) {
        LOG.error(e.getMessage());
        return 1;
    }
    System.out.println(kind + ' ' + oldname + " -> " + newname);
    return 0;
}
Also used : UniqueId(net.opentsdb.uid.UniqueId) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) HBaseException(org.hbase.async.HBaseException) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName)

Example 2 with UniqueId

use of net.opentsdb.uid.UniqueId in project opentsdb by OpenTSDB.

the class UidManager method extactLookupName.

/**
   * Looks up a name for a given kind, and prints it if found.
   * @param client The HBase client to use.
   * @param idwidth Number of bytes on which the UIDs should be.
   * @param kind The 'kind' of the ID (must not be {@code null}).
   * @param name The name to look for.
   * @return 0 if the name for this kind was found, 1 otherwise.
   */
private static int extactLookupName(final HBaseClient client, final byte[] table, final short idwidth, final String kind, final String name) {
    final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
    try {
        final byte[] id = uid.getId(name);
        System.out.println(kind + ' ' + name + ": " + Arrays.toString(id));
        return 0;
    } catch (NoSuchUniqueName e) {
        LOG.error(e.getMessage());
        return 1;
    }
}
Also used : UniqueId(net.opentsdb.uid.UniqueId) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName)

Example 3 with UniqueId

use of net.opentsdb.uid.UniqueId in project opentsdb by OpenTSDB.

the class UidManager method extactLookupId.

/**
   * Looks up an ID for a given kind, and prints it if found.
   * @param client The HBase client to use.
   * @param table The name of the HBase table to use.
   * @param idwidth Number of bytes on which the UIDs should be.
   * @param kind The 'kind' of the ID (must not be {@code null}).
   * @param id The ID to look for.
   * @return 0 if the ID for this kind was found, 1 otherwise.
   */
private static int extactLookupId(final HBaseClient client, final byte[] table, final short idwidth, final String kind, final byte[] id) {
    final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
    try {
        final String name = uid.getName(id);
        System.out.println(kind + ' ' + name + ": " + Arrays.toString(id));
        return 0;
    } catch (NoSuchUniqueId e) {
        LOG.error(e.getMessage());
        return 1;
    }
}
Also used : UniqueId(net.opentsdb.uid.UniqueId) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId)

Example 4 with UniqueId

use of net.opentsdb.uid.UniqueId in project opentsdb by OpenTSDB.

the class UidManager method assign.

/**
   * Implements the {@code assign} subcommand.
   * @param tsdb The TSDB to use.
   * @param table The name of the HBase table to use.
   * @param idwidth Number of bytes on which the UIDs should be.
   * @param args Command line arguments ({@code assign name [names]}).
   * @return The exit status of the command (0 means success).
   */
private static int assign(final TSDB tsdb, final byte[] table, final short idwidth, final String[] args) {
    boolean randomize = false;
    if (UniqueId.stringToUniqueIdType(args[1]) == UniqueIdType.METRIC) {
        randomize = tsdb.getConfig().getBoolean("tsd.core.uid.random_metrics");
    }
    final UniqueId uid = new UniqueId(tsdb.getClient(), table, args[1], (int) idwidth, randomize);
    for (int i = 2; i < args.length; i++) {
        try {
            uid.getOrCreateId(args[i]);
            // Lookup again the ID we've just created and print it.
            extactLookupName(tsdb.getClient(), table, idwidth, args[1], args[i]);
        } catch (HBaseException e) {
            LOG.error("error while processing " + args[i], e);
            return 3;
        }
    }
    return 0;
}
Also used : UniqueId(net.opentsdb.uid.UniqueId) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) HBaseException(org.hbase.async.HBaseException)

Aggregations

NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)4 UniqueId (net.opentsdb.uid.UniqueId)4 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)2 HBaseException (org.hbase.async.HBaseException)2