use of javax.ws.rs.Produces in project pinot by linkedin.
the class JobResource method listRecentJobs.
@GET
@Path("/listRecentJobs")
@Produces(MediaType.APPLICATION_JSON)
public String listRecentJobs(@DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("10") @QueryParam("jtPageSize") int jtPageSize) {
List<JobDTO> jobDTOs = jobDao.findNRecentJobs(jtStartIndex + jtPageSize);
List<JobDTO> subList = Utils.sublist(jobDTOs, jtStartIndex, jtPageSize);
ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
return rootNode.toString();
}
use of javax.ws.rs.Produces in project pinot by linkedin.
the class DashboardResource method getDashboardData.
@GET
@Path(value = "/data/customDashboard")
@Produces(MediaType.APPLICATION_JSON)
public String getDashboardData(@QueryParam("dataset") String collection, @QueryParam("dashboard") String dashboardName, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("compareMode") String compareMode, @QueryParam("aggTimeGranularity") String aggTimeGranularity) {
try {
TabularViewRequest request = new TabularViewRequest();
request.setCollection(collection);
List<MetricExpression> metricExpressions = new ArrayList<>();
DashboardConfigDTO dashboardConfig = dashboardConfigDAO.findByName(dashboardName);
List<Long> metricIds = dashboardConfig.getMetricIds();
for (Long metricId : metricIds) {
MetricConfigDTO metricConfig = metricConfigDAO.findById(metricId);
MetricExpression metricExpression = ThirdEyeUtils.getMetricExpressionFromMetricConfig(metricConfig);
metricExpressions.add(metricExpression);
}
request.setMetricExpressions(metricExpressions);
long maxDataTime = collectionMaxDataTimeCache.get(collection);
if (currentEnd > maxDataTime) {
long delta = currentEnd - maxDataTime;
currentEnd = currentEnd - delta;
baselineEnd = baselineEnd - delta;
}
// The input start and end time (i.e., currentStart, currentEnd, baselineStart, and
// baselineEnd) are given in millisecond since epoch, which is timezone insensitive. On the
// other hand, the start and end time of the request to be sent to backend database (e.g.,
// Pinot) could be converted to SimpleDateFormat, which is timezone sensitive. Therefore,
// we need to store user's start and end time in DateTime objects with data's timezone
// in order to ensure that the conversion to SimpleDateFormat is always correct regardless
// user and server's timezone, including daylight saving time.
DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
if (filterJson != null && !filterJson.isEmpty()) {
filterJson = URLDecoder.decode(filterJson, "UTF-8");
request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
}
request.setTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
TabularViewHandler handler = new TabularViewHandler(queryCache);
String jsonResponse = null;
TabularViewResponse response = handler.process(request);
jsonResponse = OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(response);
LOG.debug("customDashboard response {}", jsonResponse);
return jsonResponse;
} catch (Exception e) {
LOG.error("Exception while processing /data/tabular call", e);
return "{\"ERROR\": + " + e.getMessage() + "}";
}
}
use of javax.ws.rs.Produces in project pinot by linkedin.
the class DataCompletenessResource method getPercentCompleteness.
@GET
@Path(value = "/percent-completeness")
@Produces(MediaType.APPLICATION_JSON)
public double getPercentCompleteness(String payload) {
PercentCompletenessFunctionInput input = PercentCompletenessFunctionInput.fromJson(payload);
DataCompletenessAlgorithmName algorithm = input.getAlgorithm();
List<Long> baselineCounts = input.getBaselineCounts();
Long currentCount = input.getCurrentCount();
double percentCompleteness = 0;
double baselineTotalCount = 0;
if (CollectionUtils.isNotEmpty(baselineCounts)) {
switch(algorithm) {
case WO4W_AVERAGE:
default:
for (Long baseline : baselineCounts) {
baselineTotalCount = baselineTotalCount + baseline;
}
baselineTotalCount = baselineTotalCount / baselineCounts.size();
break;
}
}
if (baselineTotalCount != 0) {
percentCompleteness = new Double(currentCount * 100) / baselineTotalCount;
}
if (baselineTotalCount == 0 && currentCount != 0) {
percentCompleteness = 100;
}
return percentCompleteness;
}
use of javax.ws.rs.Produces in project pinot by linkedin.
the class DashboardResource method getTabularData.
@GET
@Path(value = "/data/tabular")
@Produces(MediaType.APPLICATION_JSON)
public String getTabularData(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("aggTimeGranularity") String aggTimeGranularity, @QueryParam("metrics") String metricsJson) throws Exception {
TabularViewRequest request = new TabularViewRequest();
request.setCollection(collection);
List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
request.setMetricExpressions(metricExpressions);
long maxDataTime = collectionMaxDataTimeCache.get(collection);
if (currentEnd > maxDataTime) {
long delta = currentEnd - maxDataTime;
currentEnd = currentEnd - delta;
baselineEnd = baselineEnd - delta;
}
// See {@link #getDashboardData} for the reason that the start and end time are stored in a
// DateTime object with data's timezone.
DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
if (filterJson != null && !filterJson.isEmpty()) {
filterJson = URLDecoder.decode(filterJson, "UTF-8");
request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
}
request.setTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
TabularViewHandler handler = new TabularViewHandler(queryCache);
String jsonResponse = null;
try {
TabularViewResponse response = handler.process(request);
jsonResponse = OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(response);
LOG.debug("Tabular response {}", jsonResponse);
} catch (Exception e) {
LOG.error("Exception while processing /data/tabular call", e);
}
return jsonResponse;
}
use of javax.ws.rs.Produces in project jersey by jersey.
the class SetupResource method setup.
@GET
@Produces("text/html")
public Response setup(@QueryParam("clientId") String consumerKey, @QueryParam("clientSecret") String consumerSecret) {
SimpleOAuthService.setClientIdentifier(new ClientIdentifier(consumerKey, consumerSecret));
final URI uri = UriBuilder.fromUri(uriInfo.getBaseUri()).path("tasks").build();
return Response.seeOther(uri).build();
}
Aggregations