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