Search in sources :

Example 91 with Produces

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();
}
Also used : JobDTO(com.linkedin.thirdeye.datalayer.dto.JobDTO) ObjectNode(org.codehaus.jackson.node.ObjectNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 92 with Produces

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() + "}";
    }
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) TabularViewHandler(com.linkedin.thirdeye.dashboard.views.tabular.TabularViewHandler) ArrayList(java.util.ArrayList) TabularViewResponse(com.linkedin.thirdeye.dashboard.views.tabular.TabularViewResponse) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) TabularViewRequest(com.linkedin.thirdeye.dashboard.views.tabular.TabularViewRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 93 with Produces

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;
}
Also used : PercentCompletenessFunctionInput(com.linkedin.thirdeye.completeness.checker.PercentCompletenessFunctionInput) DataCompletenessAlgorithmName(com.linkedin.thirdeye.completeness.checker.DataCompletenessConstants.DataCompletenessAlgorithmName) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 94 with Produces

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;
}
Also used : TabularViewHandler(com.linkedin.thirdeye.dashboard.views.tabular.TabularViewHandler) TabularViewResponse(com.linkedin.thirdeye.dashboard.views.tabular.TabularViewResponse) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TabularViewRequest(com.linkedin.thirdeye.dashboard.views.tabular.TabularViewRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 95 with Produces

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();
}
Also used : ClientIdentifier(org.glassfish.jersey.client.oauth2.ClientIdentifier) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Produces (javax.ws.rs.Produces)1150 Path (javax.ws.rs.Path)844 GET (javax.ws.rs.GET)724 Consumes (javax.ws.rs.Consumes)306 POST (javax.ws.rs.POST)304 ApiOperation (io.swagger.annotations.ApiOperation)275 ApiResponses (io.swagger.annotations.ApiResponses)218 IOException (java.io.IOException)143 Response (javax.ws.rs.core.Response)139 WebApplicationException (javax.ws.rs.WebApplicationException)115 URI (java.net.URI)110 TimedResource (org.killbill.commons.metrics.TimedResource)109 Timed (com.codahale.metrics.annotation.Timed)103 ArrayList (java.util.ArrayList)91 PUT (javax.ws.rs.PUT)89 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)85 HashMap (java.util.HashMap)68 Map (java.util.Map)63 UUID (java.util.UUID)63 DELETE (javax.ws.rs.DELETE)62