{
24 |
25 | /**
26 | * Returns {@code true} if this view has more elements.
27 | */
28 | boolean hasNext();
29 |
30 | /**
31 | * Returns a view on the next data point.
32 | * No new object gets created, the referenced returned is always the same
33 | * and must not be stored since its internal data structure will change the
34 | * next time {@code next()} is called.
35 | * @throws NoSuchElementException if there were no more elements to iterate
36 | * on (in which case {@link #hasNext} would have returned {@code false}.
37 | */
38 | HistogramDataPoint next();
39 |
40 | /**
41 | * Unsupported operation.
42 | * @throws UnsupportedOperationException always.
43 | */
44 | void remove();
45 |
46 | /**
47 | * Advances the iterator to the given point in time.
48 | *
49 | * This allows the iterator to skip all the data points that are strictly
50 | * before the given timestamp.
51 | * @param timestamp A strictly positive 32 bit UNIX timestamp (in seconds).
52 | * @throws IllegalArgumentException if the timestamp is zero, or negative,
53 | * or doesn't fit on 32 bits (think "unsigned int" -- yay Java!).
54 | */
55 | void seek(long timestamp);
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/query/pojo/Validatable.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2015 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.query.pojo;
14 |
15 | import java.util.Collection;
16 | import java.util.Iterator;
17 |
18 | /**
19 | * An interface for the pojos to implement to make sure all the bits of the
20 | * expression queries are there
21 | * @since 2.3
22 | */
23 | public abstract class Validatable {
24 | abstract public void validate();
25 |
26 | /**
27 | * Iterate through a field that is a collection of POJOs and validate each of
28 | * them. Inherit member POJO's error message.
29 | * @param collection the validatable POJO collection
30 | * @param name name of the field
31 | */
32 | void validateCollection(final Collection collection,
33 | final String name) {
34 | Iterator iterator = collection.iterator();
35 | int i = 0;
36 | while (iterator.hasNext()) {
37 | try {
38 | iterator.next().validate();
39 | } catch (final IllegalArgumentException e) {
40 | throw new IllegalArgumentException("Invalid " + name +
41 | " at index " + i, e);
42 | }
43 | i++;
44 | }
45 | }
46 |
47 | /**
48 | * Validate a single POJO validate
49 | * @param pojo The POJO object to validate
50 | * @param name name of the field
51 | */
52 | void validatePOJO(final T pojo, final String name) {
53 | try {
54 | pojo.validate();
55 | } catch (final IllegalArgumentException e) {
56 | throw new IllegalArgumentException("Invalid " + name, e);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/test/core/TestSaltScannerSalted.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2017 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.core;
14 |
15 | import java.util.ArrayList;
16 | import java.util.TreeMap;
17 |
18 | import net.opentsdb.query.filter.TagVFilter;
19 | import net.opentsdb.uid.UniqueId;
20 |
21 | import org.hbase.async.Scanner;
22 | import org.junit.Before;
23 | import org.junit.runner.RunWith;
24 | import org.powermock.api.mockito.PowerMockito;
25 | import org.powermock.core.classloader.annotations.PowerMockIgnore;
26 | import org.powermock.core.classloader.annotations.PrepareForTest;
27 | import org.powermock.modules.junit4.PowerMockRunner;
28 |
29 | @RunWith(PowerMockRunner.class)
30 | @PowerMockIgnore({"javax.management.*", "javax.xml.*",
31 | "ch.qos.*", "org.slf4j.*",
32 | "com.sum.*", "org.xml.*"})
33 | @PrepareForTest({ TSDB.class, Scanner.class, SaltScanner.class, Span.class,
34 | Const.class, UniqueId.class })
35 | public class TestSaltScannerSalted extends TestSaltScanner {
36 |
37 | @Before
38 | public void beforeLocal() throws Exception {
39 | PowerMockito.mockStatic(Const.class);
40 | PowerMockito.when(Const.SALT_WIDTH()).thenReturn(1);
41 | PowerMockito.when(Const.SALT_BUCKETS()).thenReturn(2);
42 |
43 | KEY_A = getRowKey(METRIC_STRING, 1356998400, TAGK_STRING, TAGV_STRING);
44 | KEY_B = getRowKey(METRIC_STRING, 1356998400, TAGK_STRING, TAGV_B_STRING);
45 | KEY_C = getRowKey(METRIC_STRING, 1359680400, TAGK_STRING, TAGV_STRING);
46 |
47 | filters = new ArrayList();
48 |
49 | spans = new TreeMap(new RowKey.SaltCmp());
50 | setupMockScanners(true);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/tsd/StaticFileRpc.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2010-2012 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.tsd;
14 |
15 | import java.io.IOException;
16 |
17 | import net.opentsdb.core.TSDB;
18 | import org.jboss.netty.handler.codec.http.HttpMethod;
19 |
20 | /** Implements the "/s" endpoint to serve static files. */
21 | final class StaticFileRpc implements HttpRpc {
22 |
23 | /**
24 | * Constructor.
25 | */
26 | public StaticFileRpc() {
27 | }
28 |
29 | public void execute(final TSDB tsdb, final HttpQuery query)
30 | throws BadRequestException, IOException {
31 |
32 | // only accept GET
33 | RpcUtil.allowedMethods(query.method(), HttpMethod.GET.getName());
34 |
35 | final String uri = query.request().getUri();
36 | if ("/favicon.ico".equals(uri)) {
37 | query.sendFile(tsdb.getConfig().getDirectoryName("tsd.http.staticroot")
38 | + "/favicon.ico", 31536000 /*=1yr*/);
39 | return;
40 | }
41 |
42 | if (uri.length() < 3) { // Must be at least 3 because of the "/s/".
43 | throw new BadRequestException("URI too short " + uri + "");
44 | }
45 | // Cheap security check to avoid directory traversal attacks.
46 | // TODO(tsuna): This is certainly not sufficient.
47 | if (uri.indexOf("..", 3) > 0) {
48 | throw new BadRequestException("Malformed URI " + uri + "");
49 | }
50 |
51 | final int questionmark = uri.indexOf('?', 3);
52 | final int pathend = questionmark > 0 ? questionmark : uri.length();
53 | query.sendFile(tsdb.getConfig().getDirectoryName("tsd.http.staticroot")
54 | + uri.substring(2, pathend), // Drop the "/s"
55 | uri.contains("nocache") ? 0 : 31536000 /*=1yr*/);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/auth/Roles.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2016-2017 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 |
14 | package net.opentsdb.auth;
15 |
16 | import java.util.*;
17 |
18 | /**
19 | * Suggested standard Roles for OpenTSDB Users
20 | *
21 | * @author jonathan.creasy
22 | * @since 2.4.0
23 | */
24 | @SuppressWarnings({"WeakerAccess", "unused"})
25 | public class Roles {
26 | final static EnumSet ADMINISTRATOR = EnumSet.allOf(Permissions.class);
27 | final static EnumSet PUTONLY = EnumSet.of(Permissions.HTTP_PUT, Permissions.TELNET_PUT);
28 | final static EnumSet WRITER = EnumSet.of(Permissions.HTTP_PUT, Permissions.TELNET_PUT, Permissions.CREATE_TAGV);
29 | final static EnumSet READER = EnumSet.of(Permissions.HTTP_QUERY);
30 | final static EnumSet CREATOR = EnumSet.of(Permissions.CREATE_METRIC, Permissions.CREATE_TAGK, Permissions.CREATE_TAGV);
31 | final static EnumSet GUEST = EnumSet.noneOf(Permissions.class);
32 |
33 | @SuppressWarnings("Convert2Diamond")
34 | private final Set> grantedPermissions = new HashSet>();
35 |
36 | public Roles() {
37 | this.grantedPermissions.add(GUEST);
38 | }
39 |
40 | public Roles(final EnumSet permissions) {
41 | this.grantedPermissions.add(permissions);
42 | }
43 |
44 | public void grantPermissions(final EnumSet permissions) {
45 | grantedPermissions.add(permissions);
46 | }
47 |
48 | public Boolean hasPermission(final Permissions permission) {
49 | for (EnumSet permissions : this.grantedPermissions) {
50 | if (permissions.contains(permission)) {
51 | return true;
52 | }
53 | }
54 | return false;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/core/SimpleHistogramDecoder.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2016-2017 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.core;
14 |
15 | import java.util.Arrays;
16 |
17 | /**
18 | *
19 | * Histogram decoder for Simple style histograms.
20 | *
21 | *
22 | * It currently checks the first byte of the encoded data and decide the type of
23 | * the histogram. Then it uses that histogram types builtin factory method to
24 | * create the instance.
25 | *
26 | *
27 | * This class is thread safe as it has no state.
28 | *
29 | * @since 2.4
30 | */
31 | public class SimpleHistogramDecoder extends HistogramDataPointCodec {
32 | @Override
33 | public Histogram decode(final byte[] raw_data,
34 | final boolean includes_type) {
35 | if (raw_data == null) {
36 | throw new IllegalArgumentException("The data array cannot be null.");
37 | }
38 | if (includes_type && raw_data.length < 1) {
39 | throw new IllegalArgumentException("The data array cannot be empty.");
40 | }
41 | if (includes_type && (int) raw_data[0] != id) {
42 | throw new IllegalArgumentException("Data ID " + (int) raw_data[0]
43 | + " did not match the codec ID " + id);
44 | }
45 | final Histogram histogram = new SimpleHistogram(id);
46 | histogram.fromHistogram(raw_data, includes_type);
47 | return histogram;
48 | }
49 |
50 | @Override
51 | public byte[] encode(final Histogram data_point,
52 | final boolean include_id) {
53 | if (!(data_point instanceof SimpleHistogram)) {
54 | throw new IllegalArgumentException("The given histogram is not a "
55 | + "SimpleHistogram: " + data_point.getClass());
56 | }
57 | return data_point.histogram(include_id);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/core/DataPoint.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2010-2012 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.core;
14 |
15 | /**
16 | * Represents a single data point.
17 | *
18 | * Implementations of this interface aren't expected to be synchronized.
19 | */
20 | public interface DataPoint {
21 |
22 | /**
23 | * Returns the timestamp (in milliseconds) associated with this data point.
24 | * @return A strictly positive, 32 bit integer.
25 | */
26 | long timestamp();
27 |
28 | /**
29 | * Tells whether or not the this data point is a value of integer type.
30 | * @return {@code true} if the {@code i}th value is of integer type,
31 | * {@code false} if it's of doubleing point type.
32 | */
33 | boolean isInteger();
34 |
35 | /**
36 | * Returns the value of the this data point as a {@code long}.
37 | * @throws ClassCastException if the {@code isInteger() == false}.
38 | */
39 | long longValue();
40 |
41 | /**
42 | * Returns the value of the this data point as a {@code double}.
43 | * @throws ClassCastException if the {@code isInteger() == true}.
44 | */
45 | double doubleValue();
46 |
47 | /**
48 | * Returns the value of the this data point as a {@code double}, even if
49 | * it's a {@code long}.
50 | * @return When {@code isInteger() == false}, this method returns the same
51 | * thing as {@link #doubleValue}. Otherwise, it returns the same thing as
52 | * {@link #longValue}'s return value casted to a {@code double}.
53 | */
54 | double toDouble();
55 |
56 | /**
57 | * Represents the number of real values behind this data point when referring
58 | * to a pre-aggregated and/or rolled up value.
59 | * @return The number of real values represented in this data point. Usually
60 | * just 1 for raw values.
61 | */
62 | long valueCount();
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/configure.ac:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2011-2024 The OpenTSDB Authors.
2 | #
3 | # This library is free software: you can redistribute it and/or modify it
4 | # under the terms of the GNU Lesser General Public License as published
5 | # by the Free Software Foundation, either version 2.1 of the License, or
6 | # (at your option) any later version.
7 | #
8 | # This library is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Lesser General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Lesser General Public License
14 | # along with this library. If not, see .
15 |
16 | # Semantic Versioning (see http://semver.org/).
17 | AC_INIT([opentsdb], [2.5.0-RC1], [opentsdb@googlegroups.com])
18 | AC_CONFIG_AUX_DIR([build-aux])
19 | AM_INIT_AUTOMAKE([foreign])
20 |
21 | AC_CONFIG_FILES([
22 | Makefile
23 | ])
24 | AC_CONFIG_FILES([opentsdb.spec])
25 | AC_CONFIG_FILES([build-aux/fetchdep.sh], [chmod +x build-aux/fetchdep.sh])
26 |
27 | AC_ARG_WITH([bigtable],
28 | [AS_HELP_STRING([--with-bigtable], [Enable Google's Bigtable backend])],
29 | [with_bigtable=yes],
30 | [with_bigtable=no])
31 |
32 | AS_IF([test "x$with_bigtable" = "xyes"],
33 | [AM_CONDITIONAL(BIGTABLE, true)],
34 | [AM_CONDITIONAL(BIGTABLE, false)]
35 | )
36 |
37 | AC_ARG_WITH([cassandra],
38 | [AS_HELP_STRING([--with-cassandra], [Enable Cassandra backend])],
39 | [with_cassandra=yes],
40 | [with_cassandra=no])
41 |
42 | AS_IF([test "x$with_cassandra" = "xyes"],
43 | [AM_CONDITIONAL(CASSANDRA, true)],
44 | [AM_CONDITIONAL(CASSANDRA, false)]
45 | )
46 |
47 | TSDB_FIND_PROG([md5], [md5sum md5 gmd5sum digest])
48 | if test x`basename "$MD5"` = x'digest'; then
49 | MD5='digest -a md5'
50 | fi
51 | TSDB_FIND_PROG([java])
52 | TSDB_FIND_PROG([javac])
53 | TSDB_FIND_PROG([jar])
54 | # Mac OS does not have gnuplot. Falls back to /usr/bin/true to make gnuplot
55 | # optional.
56 | TSDB_FIND_PROG([gnuplot], [true])
57 | AC_PATH_PROG([JAVADOC], [javadoc], [])
58 | AM_MISSING_PROG([JAVADOC], [javadoc])
59 |
60 | # Find a tool to download 3rd party dependencies.
61 | AC_PATH_PROG([WGET], [wget])
62 | AC_PATH_PROG([CURL], [curl])
63 | # Make sure we have at least one.
64 | if test -z "$WGET$CURL"; then
65 | AC_MSG_ERROR([cannot find a tool to download an URL])
66 | fi
67 |
68 | AC_SUBST([staticdir], ['${pkgdatadir}/static'])
69 |
70 | AC_OUTPUT
71 |
--------------------------------------------------------------------------------
/src/create_table.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Small script to setup the HBase tables used by OpenTSDB.
3 |
4 | test -n "$HBASE_HOME" || {
5 | echo >&2 'The environment variable HBASE_HOME must be set'
6 | exit 1
7 | }
8 | test -d "$HBASE_HOME" || {
9 | echo >&2 "No such directory: HBASE_HOME=$HBASE_HOME"
10 | exit 1
11 | }
12 |
13 | TSDB_TABLE=${TSDB_TABLE-'tsdb'}
14 | UID_TABLE=${UID_TABLE-'tsdb-uid'}
15 | TREE_TABLE=${TREE_TABLE-'tsdb-tree'}
16 | META_TABLE=${META_TABLE-'tsdb-meta'}
17 | BLOOMFILTER=${BLOOMFILTER-'ROW'}
18 | # LZO requires lzo2 64bit to be installed + the hadoop-gpl-compression jar.
19 | COMPRESSION=${COMPRESSION-'LZO'}
20 | # All compression codec names are upper case (NONE, LZO, SNAPPY, etc).
21 | COMPRESSION=`echo "$COMPRESSION" | tr a-z A-Z`
22 | # DIFF encoding is very useful for OpenTSDB's case that many small KVs and common prefix.
23 | # This can save a lot of storage space.
24 | DATA_BLOCK_ENCODING=${DATA_BLOCK_ENCODING-'DIFF'}
25 | DATA_BLOCK_ENCODING=`echo "$DATA_BLOCK_ENCODING" | tr a-z A-Z`
26 | TSDB_TTL=${TSDB_TTL-'FOREVER'}
27 |
28 | case $COMPRESSION in
29 | (NONE|LZO|GZIP|SNAPPY) :;; # Known good.
30 | (*)
31 | echo >&2 "warning: compression codec '$COMPRESSION' might not be supported."
32 | ;;
33 | esac
34 |
35 | case $DATA_BLOCK_ENCODING in
36 | (NONE|PREFIX|DIFF|FAST_DIFF|ROW_INDEX_V1) :;; # Know good
37 | (*)
38 | echo >&2 "warning: encoding '$DATA_BLOCK_ENCODING' might not be supported."
39 | ;;
40 | esac
41 |
42 | # HBase scripts also use a variable named `HBASE_HOME', and having this
43 | # variable in the environment with a value somewhat different from what
44 | # they expect can confuse them in some cases. So rename the variable.
45 | hbh=$HBASE_HOME
46 | unset HBASE_HOME
47 | exec "$hbh/bin/hbase" shell < 'id', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'},
50 | {NAME => 'name', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'}
51 |
52 | create '$TSDB_TABLE',
53 | {NAME => 't', VERSIONS => 1, COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING', TTL => '$TSDB_TTL'}
54 |
55 | create '$TREE_TABLE',
56 | {NAME => 't', VERSIONS => 1, COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'}
57 |
58 | create '$META_TABLE',
59 | {NAME => 'name', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'}
60 | EOF
61 |
--------------------------------------------------------------------------------
/test/utils/TestByteSet.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2015 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.utils;
14 |
15 | import static org.junit.Assert.assertArrayEquals;
16 | import static org.junit.Assert.assertEquals;
17 | import static org.junit.Assert.assertFalse;
18 | import static org.junit.Assert.assertNotNull;
19 | import static org.junit.Assert.assertTrue;
20 |
21 | import java.util.Iterator;
22 |
23 | import org.junit.Test;
24 |
25 | public class TestByteSet {
26 |
27 | private static final byte[] V1 = new byte[] { 0, 0, 1 };
28 | private static final byte[] V2 = new byte[] { 0, 0, 2 };
29 | private static final byte[] V3 = new byte[] { 0, 0, 3 };
30 | private static final byte[] V4 = new byte[] { 0, 0, 4 };
31 |
32 | @Test
33 | public void ctor() {
34 | final ByteSet set = new ByteSet();
35 | assertNotNull(set);
36 | assertEquals(0, set.size());
37 | assertTrue(set.isEmpty());
38 | }
39 |
40 | @Test
41 | public void goodOperations() {
42 | final ByteSet set = new ByteSet();
43 | set.add(V3);
44 | set.add(V2);
45 | set.add(V1);
46 |
47 | assertEquals(3, set.size());
48 | assertFalse(set.isEmpty());
49 |
50 | // should come out in order
51 | final Iterator it = set.iterator();
52 | assertArrayEquals(V1, it.next());
53 | assertArrayEquals(V2, it.next());
54 | assertArrayEquals(V3, it.next());
55 | assertFalse(it.hasNext());
56 |
57 | assertEquals("[[0, 0, 1],[0, 0, 2],[0, 0, 3]]", set.toString());
58 |
59 | assertTrue(set.contains(V1));
60 | assertFalse(set.contains(V4));
61 |
62 | assertTrue(set.remove(V1));
63 | assertFalse(set.contains(V1));
64 | assertFalse(set.remove(V4));
65 |
66 | set.clear();
67 | assertFalse(set.contains(V2));
68 | assertFalse(set.contains(V3));
69 | assertTrue(set.isEmpty());
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/test/search/TestSearchQuery.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2013 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.search;
14 |
15 | import static org.junit.Assert.assertEquals;
16 | import net.opentsdb.search.SearchQuery.SearchType;
17 |
18 | import org.junit.Test;
19 | import org.junit.runner.RunWith;
20 | import org.powermock.modules.junit4.PowerMockRunner;
21 |
22 | @RunWith(PowerMockRunner.class)
23 | public final class TestSearchQuery {
24 |
25 | @Test
26 | public void parseSearchTypeTSMeta() throws Exception {
27 | assertEquals(SearchType.TSMETA, SearchQuery.parseSearchType("tsmeta"));
28 | }
29 |
30 | @Test
31 | public void parseSearchTypeTSMetaSummary() throws Exception {
32 | assertEquals(SearchType.TSMETA_SUMMARY,
33 | SearchQuery.parseSearchType("TSMeta_Summary"));
34 | }
35 |
36 | @Test
37 | public void parseSearchTypeTSUIDs() throws Exception {
38 | assertEquals(SearchType.TSUIDS, SearchQuery.parseSearchType("tsuids"));
39 | }
40 |
41 | @Test
42 | public void parseSearchTypeUIDMeta() throws Exception {
43 | assertEquals(SearchType.UIDMETA, SearchQuery.parseSearchType("UIDMeta"));
44 | }
45 |
46 | @Test
47 | public void parseSearchTypeAnnotation() throws Exception {
48 | assertEquals(SearchType.ANNOTATION,
49 | SearchQuery.parseSearchType("Annotation"));
50 | }
51 |
52 | @Test (expected = IllegalArgumentException.class)
53 | public void parseSearchTypeNull() throws Exception {
54 | SearchQuery.parseSearchType(null);
55 | }
56 |
57 | @Test (expected = IllegalArgumentException.class)
58 | public void parseSearchTypeEmtpy() throws Exception {
59 | SearchQuery.parseSearchType("");
60 | }
61 |
62 | @Test (expected = IllegalArgumentException.class)
63 | public void parseSearchTypeInvalid() throws Exception {
64 | SearchQuery.parseSearchType("NotAType");
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/core/iHistogramRowSeq.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2016-2017 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.core;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * Clone of the {@link iRowSeq} interface but for histograms.
19 | *
20 | * @since 2.4
21 | */
22 | public interface iHistogramRowSeq extends HistogramDataPoints {
23 |
24 | /**
25 | * Sets the initial column in the sequence. The key cannot be empty.
26 | * @param key The row key.
27 | * @param row A non-null list of histogram points.
28 | * @throws IllegalStateException if {@link #setRow(byte[], List)} or
29 | * {@link #addRow(List)} has already been called.
30 | */
31 | public void setRow(final byte[] key, final List row);
32 |
33 | /**
34 | * Adds a column in the proper sequence in the row. Must be called after
35 | * {@link #setRow(byte[], List)} has been called.
36 | * @param row A non-null list of histogram points.
37 | * @throws IllegalStateException if {@link #setRow(byte[], List)} has not been
38 | * called first.
39 | */
40 | public void addRow(final List row);
41 |
42 | /**
43 | * Returns the row key this sequence represents. May be null if
44 | * {@link #setRow(byte[], List)} has not been called.
45 | * @return The row key for this sequence.
46 | */
47 | public byte[] key();
48 |
49 | /**
50 | * Returns the base time for the row in Unix epoch seconds.
51 | * @return The base time for the row.
52 | * @throws NullPointerException if {@link #setRow(byte[], List)} has not been
53 | * called.
54 | */
55 | public long baseTime();
56 |
57 | /** @return an internal iterator for this row sequence. */
58 | public Iterator internalIterator();
59 |
60 | /**
61 | * An interface for an iterator that all row sequences must implement.
62 | */
63 | public interface Iterator extends HistogramSeekableView, HistogramDataPoint {
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/core/iRowSeq.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2015 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.core;
14 |
15 | import org.hbase.async.KeyValue;
16 |
17 | /**
18 | * An interface that defines methods implemented by row sequence implementations
19 | * that represent a row of data in storage.
20 | * @since 2.4
21 | */
22 | public interface iRowSeq extends DataPoints {
23 |
24 | /**
25 | * Sets the initial column in the sequence. The row must be empty and this
26 | * must be called before {@link #addRow(KeyValue)}.
27 | * @param row A non-null KeyValue representing a column in the row.
28 | * @throws IllegalStateException if {@link #setRow(KeyValue)} or
29 | * {@link #addRow(KeyValue)} has already been called.
30 | */
31 | public void setRow(final KeyValue row);
32 |
33 | /**
34 | * Adds a column in the proper sequence in the row. Must be called after
35 | * {@link #setRow(KeyValue)} has been called.
36 | * @param row A non-null KeyValue representing a column in the row.
37 | * @throws IllegalStateException if {@link #setRow(KeyValue)} has not been
38 | * called first.
39 | */
40 | public void addRow(final KeyValue row);
41 |
42 | /**
43 | * Returns the row key this sequence represents. May be null if
44 | * {@link #setRow(KeyValue)} has not been called.
45 | * @return The row key for this sequence.
46 | */
47 | public byte[] key();
48 |
49 | /**
50 | * Returns the base time for the row in Unix epoch seconds.
51 | * @return The base time for the row.
52 | * @throws NullPointerException if {@link #setRow(KeyValue)} has not been
53 | * called.
54 | */
55 | public long baseTime();
56 |
57 | /** @return an internal iterator for this row sequence. */
58 | public Iterator internalIterator();
59 |
60 | /**
61 | * An interface for an iterator that all row sequences must implement.
62 | */
63 | public interface Iterator extends SeekableView, DataPoint {
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/core/QueryException.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2015 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.core;
14 |
15 | import org.jboss.netty.handler.codec.http.HttpResponseStatus;
16 |
17 | /**
18 | * An exception thrown during query execution such as a timeout or other
19 | * type of error.
20 | * @since 2.2
21 | */
22 | public final class QueryException extends RuntimeException {
23 |
24 | /** An optional, detailed error message */
25 | private final String details;
26 |
27 | /** The HTTP status code to return to the user */
28 | private final HttpResponseStatus status;
29 |
30 | /**
31 | * Default ctor
32 | * @param msg Message describing the problem.
33 | */
34 | public QueryException(final String msg) {
35 | super(msg);
36 | status = HttpResponseStatus.BAD_REQUEST;
37 | details = msg;
38 | }
39 |
40 | /**
41 | * Ctor setting the status
42 | * @param status The status code to respond with for HTTP requests
43 | * @param msg Message describing the problem.
44 | */
45 | public QueryException(final HttpResponseStatus status, final String msg) {
46 | super(msg);
47 | this.status = status;
48 | details = msg;
49 | }
50 |
51 | /**
52 | * Ctor setting status and the messages
53 | * @param status The status code to respond with for HTTP requests
54 | * @param msg Message describing the problem.
55 | * @param details Extra details for the error
56 | */
57 | public QueryException(final HttpResponseStatus status, final String msg,
58 | final String details) {
59 | super(msg);
60 | this.status = status;
61 | this.details = details;
62 | }
63 |
64 | /** @return the HTTP status code */
65 | public final HttpResponseStatus getStatus() {
66 | return this.status;
67 | }
68 |
69 | /** @return the details, may be an empty string */
70 | public final String getDetails() {
71 | return this.details;
72 | }
73 |
74 | private static final long serialVersionUID = 9040020770546069974L;
75 | }
76 |
--------------------------------------------------------------------------------
/test/utils/TestExceptions.java:
--------------------------------------------------------------------------------
1 | // This file is part of OpenTSDB.
2 | // Copyright (C) 2015 The OpenTSDB Authors.
3 | //
4 | // This program is free software: you can redistribute it and/or modify it
5 | // under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 2.1 of the License, or (at your
7 | // option) any later version. This program is distributed in the hope that it
8 | // will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
10 | // General Public License for more details. You should have received a copy
11 | // of the GNU Lesser General Public License along with this program. If not,
12 | // see .
13 | package net.opentsdb.utils;
14 |
15 | import static org.junit.Assert.assertSame;
16 | import static org.junit.Assert.fail;
17 |
18 | import java.util.ArrayList;
19 |
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import com.stumbleupon.async.Callback;
24 | import com.stumbleupon.async.Deferred;
25 | import com.stumbleupon.async.DeferredGroupException;
26 |
27 | public class TestExceptions {
28 | private ArrayList> deferreds;
29 |
30 | @Before
31 | public void before() {
32 | deferreds = new ArrayList>(1);
33 | }
34 |
35 | @Test
36 | public void oneLevel() throws Exception {
37 | final RuntimeException ex = new RuntimeException("Boo!");
38 | deferreds.add(Deferred.fromError(ex));
39 | try {
40 | Deferred.group(deferreds).join();
41 | fail("Expected a DeferredGroupException");
42 | } catch (DeferredGroupException dge) {
43 | assertSame(ex, Exceptions.getCause(dge));
44 | }
45 | }
46 |
47 | @Test
48 | public void nested() throws Exception {
49 | final RuntimeException ex = new RuntimeException("Boo!");
50 | deferreds.add(Deferred.fromError(ex));
51 |
52 | final ArrayList> deferreds2 =
53 | new ArrayList>(1);
54 | deferreds2.add(Deferred.fromResult(null));
55 |
56 | class LOne implements
57 | Callback>, ArrayList