private static ArrayNode convertStringsToJsonArray(String... strings) { ArrayNode jsonArray = JsonUtils.newArrayNode(); for (String string : strings) { jsonArray.add(string); } return jsonArray; }
/** * Get the trace information added so far. */ public static String getTraceInfo() { ArrayNode jsonTraces = JsonUtils.newArrayNode(); for (Trace trace : REQUEST_TO_TRACES_MAP.get(TRACE_ENTRY_THREAD_LOCAL.get()._requestId)) { jsonTraces.add(trace.toJson()); } return jsonTraces.toString(); }
public static org.apache.avro.Schema getAvroSchema(Schema schema) { ObjectNode avroSchema = JsonUtils.newObjectNode(); avroSchema.put("name", "data_gen_record"); avroSchema.put("type", "record"); ArrayNode fields = JsonUtils.newArrayNode(); for (FieldSpec fieldSpec : schema.getAllFieldSpecs()) { JsonNode jsonObject = fieldSpec.toAvroSchemaJsonObject(); fields.add(jsonObject); } avroSchema.set("fields", fields); return new org.apache.avro.Schema.Parser().parse(avroSchema.toString()); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/schemas") @ApiOperation(value = "List all schema names", notes = "Lists all schema names") public String listSchemaNames() { List<String> schemaNames = _pinotHelixResourceManager.getSchemaNames(); ArrayNode ret = JsonUtils.newArrayNode(); if (schemaNames != null) { for (String schema : schemaNames) { ret.add(schema); } } return ret.toString(); }
JsonNode toJson() { ArrayNode jsonLogs = JsonUtils.newArrayNode(); for (LogEntry log : _logs) { jsonLogs.add(log.toJson()); } return JsonUtils.newObjectNode().set(_traceId, jsonLogs); } }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/segments") @Deprecated public String listAllSegmentNames() throws Exception { FileUploadPathProvider provider = new FileUploadPathProvider(_controllerConf); ArrayNode ret = JsonUtils.newArrayNode(); for (final File file : provider.getBaseDataDir().listFiles()) { final String fileName = file.getName(); if (fileName.equalsIgnoreCase("fileUploadTemp") || fileName.equalsIgnoreCase("schemasTemp")) { continue; } final String url = _controllerConf.generateVipUrl() + "/segments/" + fileName; ret.add(url); } return ret.toString(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/segments/{tableName}") @ApiOperation(value = "Lists names of all segments of a table", notes = "Lists names of all segment names of a table") public String listAllSegmentNames( @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) { ArrayNode ret = JsonUtils.newArrayNode(); CommonConstants.Helix.TableType tableType = Constants.validateTableType(tableTypeStr); if (tableTypeStr == null) { ret.add(formatSegments(tableName, CommonConstants.Helix.TableType.OFFLINE)); ret.add(formatSegments(tableName, CommonConstants.Helix.TableType.REALTIME)); } else { ret.add(formatSegments(tableName, tableType)); } return ret.toString(); }
jsonSchema.put("schemaName", _schemaName); if (!_dimensionFieldSpecs.isEmpty()) { ArrayNode jsonArray = JsonUtils.newArrayNode(); for (DimensionFieldSpec dimensionFieldSpec : _dimensionFieldSpecs) { jsonArray.add(dimensionFieldSpec.toJsonObject()); ArrayNode jsonArray = JsonUtils.newArrayNode(); for (MetricFieldSpec metricFieldSpec : _metricFieldSpecs) { jsonArray.add(metricFieldSpec.toJsonObject()); ArrayNode jsonArray = JsonUtils.newArrayNode(); for (DateTimeFieldSpec dateTimeFieldSpec : _dateTimeFieldSpecs) { jsonArray.add(dateTimeFieldSpec.toJsonObject());
private String listSegmentMetadataInternal(@Nonnull String tableName, @Nonnull String segmentName, @Nullable CommonConstants.Helix.TableType tableType) { List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, tableType); ArrayNode result = JsonUtils.newArrayNode(); for (String tableNameWithType : tableNamesWithType) { ArrayNode segmentMetaData = getSegmentMetaData(tableNameWithType, segmentName); if (segmentMetaData != null) { result.add(segmentMetaData); } } if (result.size() == 0) { String errorMessage = "Failed to find segment: " + segmentName + " in table: " + tableName; if (tableType != null) { errorMessage += " of type: " + tableType; } throw new ControllerApplicationException(LOGGER, errorMessage, Response.Status.NOT_FOUND); } return result.toString(); }
@Override public String dumpSnapshot(String tableName) throws Exception { ObjectNode ret = JsonUtils.newObjectNode(); ArrayNode routingTableSnapshot = JsonUtils.newArrayNode(); for (String currentTable : _routingTableBuilderMap.keySet()) { if (tableName == null || currentTable.startsWith(tableName)) { ObjectNode tableEntry = JsonUtils.newObjectNode(); tableEntry.put("tableName", currentTable); ArrayNode entries = JsonUtils.newArrayNode(); RoutingTableBuilder routingTableBuilder = _routingTableBuilderMap.get(currentTable); List<Map<String, List<String>>> routingTables = routingTableBuilder.getRoutingTables(); for (Map<String, List<String>> routingTable : routingTables) { entries.add(JsonUtils.objectToJsonNode(routingTable)); } tableEntry.set("routingTableEntries", entries); routingTableSnapshot.add(tableEntry); } } ret.set("routingTableSnapshot", routingTableSnapshot); ret.put("host", NetUtil.getHostnameOrAddress()); return JsonUtils.objectToPrettyString(ret); } }
ObjectNode ret = JsonUtils.newObjectNode(); ret.put("tableName", tableName); ArrayNode brokers = JsonUtils.newArrayNode(); ArrayNode servers = JsonUtils.newArrayNode(); ObjectNode e = JsonUtils.newObjectNode(); e.put("tableType", "offline"); ArrayNode a = JsonUtils.newArrayNode(); for (String ins : pinotHelixResourceManager.getBrokerInstancesForTable(tableName, TableType.OFFLINE)) { a.add(ins); ObjectNode e = JsonUtils.newObjectNode(); e.put("tableType", "realtime"); ArrayNode a = JsonUtils.newArrayNode(); for (String ins : pinotHelixResourceManager.getBrokerInstancesForTable(tableName, TableType.REALTIME)) { a.add(ins); ObjectNode e = JsonUtils.newObjectNode(); e.put("tableType", "offline"); ArrayNode a = JsonUtils.newArrayNode(); for (String ins : pinotHelixResourceManager.getServerInstancesForTable(tableName, TableType.OFFLINE)) { a.add(ins); ObjectNode e = JsonUtils.newObjectNode(); e.put("tableType", "realtime"); ArrayNode a = JsonUtils.newArrayNode(); for (String ins : pinotHelixResourceManager.getServerInstancesForTable(tableName, TableType.REALTIME)) { a.add(ins);
segmentMetadata.put("hllLog2m", _hllLog2m); ArrayNode columnsMetadata = JsonUtils.newArrayNode(); for (String column : _allColumns) { if (columnFilter != null && !columnFilter.contains(column)) {
private String getInstanceToSegmentsMap(@Nonnull String tableName, @Nullable CommonConstants.Helix.TableType tableType) { List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, tableType); ArrayNode result = JsonUtils.newArrayNode(); for (String tableNameWithType : tableNamesWithType) { ObjectNode resultForTable = JsonUtils.newObjectNode(); resultForTable.put(FileUploadPathProvider.TABLE_NAME, tableNameWithType); try { // NOTE: for backward-compatibility, we put serialized map string as the value resultForTable.put("segments", JsonUtils.objectToString(_pinotHelixResourceManager.getServerToSegmentsMap(tableNameWithType))); } catch (JsonProcessingException e) { throw new ControllerApplicationException(LOGGER, "Caught JSON exception while getting instance to segments map for table: " + tableNameWithType, Response.Status.INTERNAL_SERVER_ERROR, e); } result.add(resultForTable); } return result.toString(); }
ArrayNode ret = JsonUtils.newArrayNode(); boolean tableExists = false;
private ArrayNode getSegments(String tableName, String tableType) { ArrayNode segments = JsonUtils.newArrayNode(); String realtimeTableName = TableNameBuilder.REALTIME.tableNameWithType(tableName); String offlineTableName = TableNameBuilder.OFFLINE.tableNameWithType(tableName); String tableNameWithType; if (CommonConstants.Helix.TableType.valueOf(tableType).toString().equals("REALTIME")) { tableNameWithType = realtimeTableName; } else { tableNameWithType = offlineTableName; } List<String> segmentList = _pinotHelixResourceManager.getSegmentsFor(tableNameWithType); IdealState idealState = HelixHelper.getTableIdealState(_pinotHelixResourceManager.getHelixZkManager(), tableNameWithType); for (String segmentName : segmentList) { Map<String, String> map = idealState.getInstanceStateMap(segmentName); if (map == null) { continue; } if (!map.containsValue(PinotHelixSegmentOnlineOfflineStateModelGenerator.OFFLINE_STATE)) { segments.add(segmentName); } } return segments; }
/** * Returns the segment metadata. * * @param tableNameWithType Table name with type suffix * @param segmentName Segment name * @return Singleton JSON array of the segment metadata */ private ArrayNode getSegmentMetaData(String tableNameWithType, String segmentName) { ZkHelixPropertyStore<ZNRecord> propertyStore = _pinotHelixResourceManager.getPropertyStore(); if (!ZKMetadataProvider.isSegmentExisted(propertyStore, tableNameWithType, segmentName)) { return null; } ArrayNode ret = JsonUtils.newArrayNode(); ObjectNode jsonObj = JsonUtils.newObjectNode(); jsonObj.put(TABLE_NAME, tableNameWithType); if (TableNameBuilder.OFFLINE.tableHasTypeSuffix(tableNameWithType)) { // OFFLINE table OfflineSegmentZKMetadata offlineSegmentZKMetadata = ZKMetadataProvider.getOfflineSegmentZKMetadata(propertyStore, tableNameWithType, segmentName); jsonObj.set(STATE, JsonUtils.objectToJsonNode(offlineSegmentZKMetadata.toMap())); } else { // REALTIME table RealtimeSegmentZKMetadata realtimeSegmentZKMetadata = ZKMetadataProvider.getRealtimeSegmentZKMetadata(propertyStore, tableNameWithType, segmentName); jsonObj.set(STATE, JsonUtils.objectToJsonNode(realtimeSegmentZKMetadata.toMap())); } ret.add(jsonObj); return ret; }
public static String toggleStateInternal(@Nonnull String tableName, StateType state, CommonConstants.Helix.TableType tableType, String segmentName, PinotHelixResourceManager helixResourceManager) { ArrayNode ret = JsonUtils.newArrayNode(); List<String> segmentsToToggle = new ArrayList<>(); String offlineTableName = TableNameBuilder.OFFLINE.tableNameWithType(tableName);