Search in sources :

Example 11 with NoSuchUniqueId

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

the class TestTags method setupResolveIds.

private void setupResolveIds() throws Exception {
    when(tag_names.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("host"));
    when(tag_names.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("tagk", new byte[] { 0, 0, 2 }));
    when(tag_values.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("web01"));
    when(tag_values.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("tagv", new byte[] { 0, 0, 2 }));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId)

Example 12 with NoSuchUniqueId

use of net.opentsdb.uid.NoSuchUniqueId 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 13 with NoSuchUniqueId

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

the class TestFsck method noSuchMetricId.

@Test
public void noSuchMetricId() throws Exception {
    when(options.fix()).thenReturn(true);
    when(metrics.getNameAsync((byte[]) any())).thenThrow(new NoSuchUniqueId("metric", new byte[] { 0, 0, 1 }));
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    final byte[] qual2 = { 0x00, 0x27 };
    final byte[] val2 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 5 };
    storage.addColumn(ROW, qual1, val1);
    storage.addColumn(ROW, qual2, val2);
    final Fsck fsck = new Fsck(tsdb, options);
    fsck.runFullTable();
    assertEquals(0, fsck.kvs_processed.get());
    assertEquals(0, fsck.rows_processed.get());
    assertEquals(1, fsck.totalErrors());
    assertEquals(1, fsck.correctable());
    assertArrayEquals(val1, storage.getColumn(ROW, qual1));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with NoSuchUniqueId

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

the class TestFsck method noSuchTagId.

@SuppressWarnings("unchecked")
@Test
public void noSuchTagId() throws Exception {
    when(options.fix()).thenReturn(true);
    when(Tags.resolveIds((TSDB) any(), (ArrayList<byte[]>) any())).thenThrow(new NoSuchUniqueId("tagk", new byte[] { 0, 0, 1 }));
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    final byte[] qual2 = { 0x00, 0x27 };
    final byte[] val2 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 5 };
    storage.addColumn(ROW, qual1, val1);
    storage.addColumn(ROW, qual2, val2);
    final Fsck fsck = new Fsck(tsdb, options);
    fsck.runFullTable();
    assertEquals(0, fsck.kvs_processed.get());
    assertEquals(0, fsck.rows_processed.get());
    assertEquals(1, fsck.totalErrors());
    assertEquals(1, fsck.correctable());
    assertArrayEquals(val1, storage.getColumn(ROW, qual1));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with NoSuchUniqueId

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

the class TestFsck method noSuchMetricIdFix.

@Test
public void noSuchMetricIdFix() throws Exception {
    when(options.fix()).thenReturn(true);
    when(options.deleteOrphans()).thenReturn(true);
    when(metrics.getNameAsync((byte[]) any())).thenThrow(new NoSuchUniqueId("metric", new byte[] { 0, 0, 1 }));
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    final byte[] qual2 = { 0x00, 0x27 };
    final byte[] val2 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 5 };
    storage.addColumn(ROW, qual1, val1);
    storage.addColumn(ROW, qual2, val2);
    final Fsck fsck = new Fsck(tsdb, options);
    fsck.runFullTable();
    assertEquals(0, fsck.kvs_processed.get());
    assertEquals(0, fsck.rows_processed.get());
    assertEquals(1, fsck.totalErrors());
    assertEquals(1, fsck.correctable());
    assertNull(storage.getColumn(ROW, qual1));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)17 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Deferred (com.stumbleupon.async.Deferred)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)4 DataPoints (net.opentsdb.core.DataPoints)3 TSQuery (net.opentsdb.core.TSQuery)3 Annotation (net.opentsdb.meta.Annotation)3 MockDataPoints (net.opentsdb.storage.MockDataPoints)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Callback (com.stumbleupon.async.Callback)2 List (java.util.List)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Pattern (java.util.regex.Pattern)1