Search in sources :

Example 76 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project pinot by linkedin.

the class PinotSegmentRestletResource method getAllSegmentsMetadataForTable.

@HttpVerb("get")
@Summary("Lists segment metadata for a given table")
@Tags({ "segment", "table" })
@Paths({ "/tables/{tableName}/segments/metadata", "/tables/{tableName}/segments/metadata/" })
@Responses({ @Response(statusCode = "200", description = "A list of segment metadata"), @Response(statusCode = "404", description = "The table does not exist") })
private Representation getAllSegmentsMetadataForTable(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to list segment metadata", required = true) String tableName, @Parameter(name = "type", in = "query", description = "Type of table {offline|realtime}", required = false) String tableType) throws JSONException, JsonProcessingException {
    boolean foundRealtimeTable = false;
    boolean foundOfflineTable = false;
    JSONArray ret = new JSONArray();
    if ((tableType == null || TableType.REALTIME.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
        String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
        JSONObject realtime = new JSONObject();
        realtime.put(TABLE_NAME, realtimeTableName);
        realtime.put("segments", new ObjectMapper().writeValueAsString(_pinotHelixResourceManager.getInstanceToSegmentsInATableMap(realtimeTableName)));
        ret.put(realtime);
        foundRealtimeTable = true;
    }
    if ((tableType == null || TableType.OFFLINE.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
        String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
        JSONObject offline = new JSONObject();
        offline.put(TABLE_NAME, offlineTableName);
        offline.put("segments", new ObjectMapper().writeValueAsString(_pinotHelixResourceManager.getInstanceToSegmentsInATableMap(offlineTableName)));
        ret.put(offline);
        foundOfflineTable = true;
    }
    if (foundOfflineTable || foundRealtimeTable) {
        return new StringRepresentation(ret.toString());
    } else {
        setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        return new StringRepresentation("Table " + tableName + " not found.");
    }
}
Also used : JSONObject(org.json.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(org.json.JSONArray) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Summary(com.linkedin.pinot.common.restlet.swagger.Summary) HttpVerb(com.linkedin.pinot.common.restlet.swagger.HttpVerb) Paths(com.linkedin.pinot.common.restlet.swagger.Paths) Tags(com.linkedin.pinot.common.restlet.swagger.Tags) Responses(com.linkedin.pinot.common.restlet.swagger.Responses)

Example 77 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project pinot by linkedin.

the class Cube method fromJson.

public static Cube fromJson(String fileName) throws IOException {
    Cube cube = new ObjectMapper().readValue(new File(fileName), Cube.class);
    cube.buildHierarchy();
    return cube;
}
Also used : File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 78 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project pinot by linkedin.

the class AutoLoadPinotMetricsUtils method getAllTablesFromPinot.

public JsonNode getAllTablesFromPinot() throws IOException {
    HttpGet tablesReq = new HttpGet(PINOT_TABLES_ENDPOINT);
    LOG.info("Retrieving datasets: {}", tablesReq);
    CloseableHttpResponse tablesRes = pinotControllerClient.execute(pinotControllerHost, tablesReq);
    JsonNode tables = null;
    try {
        if (tablesRes.getStatusLine().getStatusCode() != 200) {
            throw new IllegalStateException(tablesRes.getStatusLine().toString());
        }
        InputStream tablesContent = tablesRes.getEntity().getContent();
        tables = new ObjectMapper().readTree(tablesContent).get("tables");
    } catch (Exception e) {
        LOG.error("Exception in loading collections", e);
    } finally {
        if (tablesRes.getEntity() != null) {
            EntityUtils.consume(tablesRes.getEntity());
        }
        tablesRes.close();
    }
    return tables;
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 79 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project pinot by linkedin.

the class AnomalyResource method viewRawAnomaliesInRange.

//View raw anomalies for collection
@GET
@Path("/raw-anomalies/view")
@Produces(MediaType.APPLICATION_JSON)
public String viewRawAnomaliesInRange(@QueryParam("functionId") String functionId, @QueryParam("dataset") String dataset, @QueryParam("startTimeIso") String startTimeIso, @QueryParam("endTimeIso") String endTimeIso, @QueryParam("metric") String metric) throws JsonProcessingException {
    if (StringUtils.isBlank(functionId) && StringUtils.isBlank(dataset)) {
        throw new IllegalArgumentException("must provide dataset or functionId");
    }
    DateTime endTime = DateTime.now();
    if (StringUtils.isNotEmpty(endTimeIso)) {
        endTime = ISODateTimeFormat.dateTimeParser().parseDateTime(endTimeIso);
    }
    DateTime startTime = endTime.minusDays(7);
    if (StringUtils.isNotEmpty(startTimeIso)) {
        startTime = ISODateTimeFormat.dateTimeParser().parseDateTime(startTimeIso);
    }
    List<RawAnomalyResultDTO> rawAnomalyResults = new ArrayList<>();
    if (StringUtils.isNotBlank(functionId)) {
        rawAnomalyResults = rawAnomalyResultDAO.findAllByTimeAndFunctionId(startTime.getMillis(), endTime.getMillis(), Long.valueOf(functionId));
    } else if (StringUtils.isNotBlank(dataset)) {
        List<AnomalyFunctionDTO> anomalyFunctions = anomalyFunctionDAO.findAllByCollection(dataset);
        List<Long> functionIds = new ArrayList<>();
        for (AnomalyFunctionDTO anomalyFunction : anomalyFunctions) {
            if (StringUtils.isNotBlank(metric) && !anomalyFunction.getTopicMetric().equals(metric)) {
                continue;
            }
            functionIds.add(anomalyFunction.getId());
        }
        for (Long id : functionIds) {
            rawAnomalyResults.addAll(rawAnomalyResultDAO.findAllByTimeAndFunctionId(startTime.getMillis(), endTime.getMillis(), id));
        }
    }
    String response = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(rawAnomalyResults);
    return response;
}
Also used : RawAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 80 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project pinot by linkedin.

the class Summary method main.

public static void main(String[] argc) {
    String oFileName = "Cube.json";
    int answerSize = 10;
    boolean doOneSideError = true;
    int maxDimensionSize = 3;
    Cube cube = null;
    try {
        cube = Cube.fromJson(oFileName);
        System.out.println("Restored Cube:");
        System.out.println(cube);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Summary summary = new Summary(cube);
    try {
        SummaryResponse response = summary.computeSummary(answerSize, doOneSideError, maxDimensionSize);
        System.out.print("JSon String: ");
        System.out.println(new ObjectMapper().writeValueAsString(response));
        System.out.println("Object String: ");
        System.out.println(response.toString());
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    summary.testCorrectnessOfWowValues();
}
Also used : Cube(com.linkedin.thirdeye.client.diffsummary.Cube) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6071 Test (org.junit.Test)2235 IOException (java.io.IOException)1016 JsonNode (com.fasterxml.jackson.databind.JsonNode)930 HashMap (java.util.HashMap)444 Map (java.util.Map)429 ArrayList (java.util.ArrayList)416 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)388 File (java.io.File)319 List (java.util.List)268 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)254 Before (org.junit.Before)246 Test (org.junit.jupiter.api.Test)238 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 InputStream (java.io.InputStream)185 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)156 Matchers.containsString (org.hamcrest.Matchers.containsString)136 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)123 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)121