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