Search in sources :

Example 6 with ItemNotFoundException

use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.

the class TestMemStorageEngine method testQueryDataPoints.

@Test
public void testQueryDataPoints() throws IOException, ItemNotFoundException {
    StorageEngine engine = new MemStorageEngine();
    engine.configure(conf, bgTasks);
    long ts = System.currentTimeMillis();
    Map<String, Measurement> db = engine.getOrCreateDatabase("test", 24);
    assertEquals(0, db.size());
    engine.writeDataPoint(MiscUtils.buildDataPoint("test", "cpu", "value", Arrays.asList("test=1"), ts, 1));
    engine.writeDataPoint(MiscUtils.buildDataPoint("test", "cpu", "value", Arrays.asList("test=1"), ts + (400 * 60000), 4));
    assertEquals(1, engine.getOrCreateMeasurement("test", "cpu").getSeriesKeys().size());
    List<Series> queryDataPoints = engine.queryDataPoints("test", "cpu", "value", ts, ts + (400 * 60000), null, null);
    assertEquals(2, queryDataPoints.iterator().next().getDataPoints().size());
    assertEquals(ts, queryDataPoints.iterator().next().getDataPoints().get(0).getTimestamp());
    assertEquals(ts + (400 * 60000), queryDataPoints.iterator().next().getDataPoints().get(1).getTimestamp());
    assertTrue(!engine.isMeasurementFieldFP("test", "cpu", "value"));
    try {
        engine.isMeasurementFieldFP("test", "test", "test");
        fail("Measurement should not exist");
    } catch (Exception e) {
    }
    try {
        engine.dropDatabase("test");
    } catch (Exception e) {
    }
    assertEquals(0, engine.getOrCreateMeasurement("test", "cpu").getTimeSeries().size());
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) Series(com.srotya.sidewinder.core.storage.Series) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with ItemNotFoundException

use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.

the class GrafanaQueryApi method queryTagKeys.

@Path("/query/tags")
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public Set<String> queryTagKeys(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, String queryString) {
    logger.log(Level.FINE, () -> "Query tags for db:" + dbName + "\t" + queryString);
    if (queryString == null || queryString.trim().isEmpty()) {
        throw new BadRequestException();
    }
    try {
        Gson gson = new Gson();
        JsonObject measurement = gson.fromJson(queryString, JsonObject.class);
        if (measurement.has("target")) {
            return engine.getTagKeysForMeasurement(dbName, measurement.get("target").getAsString());
        } else {
            throw new ItemNotFoundException("Bad request");
        }
    } catch (ItemNotFoundException e) {
        throw new NotFoundException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        throw new InternalServerErrorException(e.getMessage());
    }
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) SQLException(java.sql.SQLException) RejectException(com.srotya.sidewinder.core.storage.RejectException) BadRequestException(javax.ws.rs.BadRequestException) ParseException(java.text.ParseException) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 8 with ItemNotFoundException

use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.

the class GrafanaQueryApi method queryTagValues.

@Path("/query/tagvs")
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public Set<String> queryTagValues(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, String queryString) {
    logger.log(Level.FINE, () -> "Query tag values for db:" + dbName + "\t" + queryString);
    if (queryString == null || queryString.trim().isEmpty()) {
        throw new BadRequestException();
    }
    try {
        Gson gson = new Gson();
        JsonObject measurement = gson.fromJson(queryString, JsonObject.class);
        if (measurement.has("target")) {
            return engine.getTagValuesForMeasurement(dbName, measurement.get("target").getAsString(), measurement.get("tag").getAsString());
        } else {
            throw new ItemNotFoundException("Bad request");
        }
    } catch (ItemNotFoundException e) {
        throw new NotFoundException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        throw new InternalServerErrorException(e.getMessage());
    }
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) SQLException(java.sql.SQLException) RejectException(com.srotya.sidewinder.core.storage.RejectException) BadRequestException(javax.ws.rs.BadRequestException) ParseException(java.text.ParseException) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 9 with ItemNotFoundException

use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.

the class GrafanaUtils method queryAndGetData.

public static void queryAndGetData(StorageEngine engine, String dbName, long startTs, long endTs, List<Target> output, TargetSeries targetSeriesEntry) throws IOException {
    List<Series> points;
    try {
        points = engine.queryDataPoints(dbName, targetSeriesEntry.getMeasurementName(), targetSeriesEntry.getFieldName(), startTs, endTs, targetSeriesEntry.getTagFilter(), null, targetSeriesEntry.getAggregationFunction());
    } catch (ItemNotFoundException e) {
        throw new NotFoundException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        throw new BadRequestException(e.getMessage());
    }
    if (points != null) {
        for (Series entry : points) {
            Target tar = new Target(entry.toString());
            List<DataPoint> dps = entry.getDataPoints();
            if (dps != null) {
                for (DataPoint point : dps) {
                    if (!entry.isFp()) {
                        tar.getDatapoints().add(new Number[] { point.getLongValue(), point.getTimestamp() });
                    } else {
                        tar.getDatapoints().add(new Number[] { point.getValue(), point.getTimestamp() });
                    }
                }
            }
            output.add(tar);
            tar.sort();
        }
    }
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException)

Example 10 with ItemNotFoundException

use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.

the class TestDiskStorageEngine method testMetadataOperations.

@Test
public void testMetadataOperations() throws Exception {
    MiscUtils.delete(new File("target/dst-3/"));
    StorageEngine engine = new DiskStorageEngine();
    Map<String, String> conf = new HashMap<>();
    conf.put("data.dir", "target/dst-3/data");
    conf.put("index.dir", "target/dst-3/index");
    engine.configure(conf, bgTasks);
    engine.getOrCreateTimeSeries("db1", "m1", "vf1", Arrays.asList("t=1"), 4096, false);
    assertEquals(1, engine.getAllMeasurementsForDb("db1").size());
    assertEquals(1, engine.getTagKeysForMeasurement("db1", "m1").size());
    assertEquals(1, engine.getTagsForMeasurement("db1", "m1", "vf1").size());
    try {
        engine.getAllMeasurementsForDb("db2");
        fail("Exception must be thrown");
    } catch (ItemNotFoundException e) {
    }
    try {
        engine.getTagKeysForMeasurement("db1", "m2");
        fail("Exception must be thrown");
    } catch (ItemNotFoundException e) {
    }
    assertEquals(1, engine.getTagsForMeasurement("db1", "m1", "vf2").size());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) File(java.io.File) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) Test(org.junit.Test)

Aggregations

ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)15 IOException (java.io.IOException)13 RejectException (com.srotya.sidewinder.core.storage.RejectException)9 Series (com.srotya.sidewinder.core.storage.Series)8 NotFoundException (javax.ws.rs.NotFoundException)8 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)7 BadRequestException (javax.ws.rs.BadRequestException)7 Test (org.junit.Test)7 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)6 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)6 Gson (com.google.gson.Gson)5 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)5 File (java.io.File)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 JsonObject (com.google.gson.JsonObject)4 Point (com.srotya.sidewinder.core.rpc.Point)4 Consumes (javax.ws.rs.Consumes)4