use of com.linkedin.pinot.common.restlet.swagger.Tags in project pinot by linkedin.
the class PinotTableInstances method getTableInstances.
@HttpVerb("get")
@Summary("Lists table instances for a given table")
@Tags({ "instance", "table" })
@Paths({ "/tables/{tableName}/instances" })
private Representation getTableInstances(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to list instances", required = true) String tableName, String type) throws JSONException, IOException {
JSONObject ret = new JSONObject();
ret.put("tableName", tableName);
JSONArray brokers = new JSONArray();
JSONArray servers = new JSONArray();
if (type == null || type.toLowerCase().equals("broker")) {
if (_pinotHelixResourceManager.hasOfflineTable(tableName)) {
JSONObject e = new JSONObject();
e.put("tableType", "offline");
JSONArray a = new JSONArray();
for (String ins : _pinotHelixResourceManager.getBrokerInstancesForTable(tableName, TableType.OFFLINE)) {
a.add(ins);
}
e.put("instances", a);
brokers.add(e);
}
if (_pinotHelixResourceManager.hasRealtimeTable(tableName)) {
JSONObject e = new JSONObject();
e.put("tableType", "realtime");
JSONArray a = new JSONArray();
for (String ins : _pinotHelixResourceManager.getBrokerInstancesForTable(tableName, TableType.REALTIME)) {
a.add(ins);
}
e.put("instances", a);
brokers.add(e);
}
}
if (type == null || type.toLowerCase().equals("server")) {
if (_pinotHelixResourceManager.hasOfflineTable(tableName)) {
JSONObject e = new JSONObject();
e.put("tableType", "offline");
JSONArray a = new JSONArray();
for (String ins : _pinotHelixResourceManager.getServerInstancesForTable(tableName, TableType.OFFLINE)) {
a.add(ins);
}
e.put("instances", a);
servers.add(e);
}
if (_pinotHelixResourceManager.hasRealtimeTable(tableName)) {
JSONObject e = new JSONObject();
e.put("tableType", "realtime");
JSONArray a = new JSONArray();
for (String ins : _pinotHelixResourceManager.getServerInstancesForTable(tableName, TableType.REALTIME)) {
a.add(ins);
}
e.put("instances", a);
servers.add(e);
}
}
ret.put("brokers", brokers);
ret.put("server", servers);
return new StringRepresentation(ret.toString());
}
use of com.linkedin.pinot.common.restlet.swagger.Tags in project pinot by linkedin.
the class PinotTableMetadataConfigs method updateTableMetadata.
@Deprecated
@HttpVerb("put")
@Summary("DEPRECATED: Updates the metadata configuration for a table")
@Tags({ "table" })
@Paths({ "/tables/{tableName}/metadataConfigs" })
private Representation updateTableMetadata(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to update the metadata configuration", required = true) String tableName, Representation entity) throws Exception {
AbstractTableConfig config = AbstractTableConfig.init(entity.getText());
_pinotHelixResourceManager.updateMetadataConfigFor(config.getTableName(), TableType.valueOf(config.getTableType().toUpperCase()), config.getCustomConfigs());
return new StringRepresentation("done");
}
use of com.linkedin.pinot.common.restlet.swagger.Tags in project pinot by linkedin.
the class PinotTableRestletResource method updateTableConfig.
/*
* NOTE: There is inconsistency in these APIs. GET returns OFFLINE + REALTIME configuration
* in a single response but POST and this PUT request only operate on either offline or realtime
* table configuration. If we make this API take both realtime and offline table configuration
* then the update is not guaranteed to be transactional for both table types. This is more of a PATCH request
* than PUT.
*/
@HttpVerb("put")
@Summary("Update table configuration. Request body is offline or realtime table configuration")
@Tags({ "Table" })
@Paths({ "/tables/{tableName}" })
public Representation updateTableConfig(@Parameter(name = "tableName", in = "path", description = "Table name (without type)") String tableName, Representation entity) {
AbstractTableConfig config = null;
try {
config = AbstractTableConfig.init(entity.getText());
} catch (JSONException e) {
errorResponseRepresentation(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid json in table configuration");
} catch (IOException e) {
LOGGER.error("Failed to read request body while updating configuration for table: {}", tableName, e);
errorResponseRepresentation(Status.SERVER_ERROR_INTERNAL, "Failed to read request");
}
try {
String tableTypeStr = config.getTableType();
TableType tableType = TableType.valueOf(tableTypeStr.toUpperCase());
String configTableName = config.getTableName();
if (!configTableName.equals(tableName)) {
errorResponseRepresentation(Status.CLIENT_ERROR_BAD_REQUEST, "Request table name does not match table name in the body");
}
String tableNameWithType = null;
if (config.getTableType().equalsIgnoreCase(TableType.OFFLINE.name())) {
tableNameWithType = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
} else if (config.getTableType().equalsIgnoreCase(TableType.REALTIME.name())) {
tableNameWithType = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
}
_pinotHelixResourceManager.setTableConfig(config, tableNameWithType, tableType);
return responseRepresentation(Status.SUCCESS_OK, "{\"status\" : \"Success\"}");
} catch (IOException e) {
LOGGER.error("Failed to update table configuration for table: {}", tableName, e);
return errorResponseRepresentation(Status.SERVER_ERROR_INTERNAL, "Internal error while updating table configuration");
}
}
use of com.linkedin.pinot.common.restlet.swagger.Tags in project pinot by linkedin.
the class PinotTableRestletResource method getTable.
@HttpVerb("get")
@Summary("Views a table's configuration")
@Tags({ "table" })
@Paths({ "/tables/{tableName}", "/tables/{tableName}/" })
private Representation getTable(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to toggle its state", required = true) String tableName, @Parameter(name = "type", in = "query", description = "Type of table, Offline or Realtime", required = true) String tableType) throws JSONException, JsonParseException, JsonMappingException, JsonProcessingException, IOException {
JSONObject ret = new JSONObject();
if ((tableType == null || TableType.OFFLINE.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
AbstractTableConfig config = _pinotHelixResourceManager.getTableConfig(tableName, TableType.OFFLINE);
ret.put(TableType.OFFLINE.name(), config.toJSON());
}
if ((tableType == null || TableType.REALTIME.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
AbstractTableConfig config = _pinotHelixResourceManager.getTableConfig(tableName, TableType.REALTIME);
ret.put(TableType.REALTIME.name(), config.toJSON());
}
return new StringRepresentation(ret.toString(2));
}
use of com.linkedin.pinot.common.restlet.swagger.Tags in project pinot by linkedin.
the class PinotTableRestletResource method addTable.
@HttpVerb("post")
@Summary("Adds a table")
@Tags({ "table" })
@Paths({ "/tables", "/tables/" })
private void addTable(AbstractTableConfig config) throws IOException {
// For self-serviced cluster, ensure that the tables are created with atleast
// min replication factor irrespective of table configuratio value.
SegmentsValidationAndRetentionConfig segmentsConfig = config.getValidationConfig();
int requestReplication = segmentsConfig.getReplicationNumber();
int configMinReplication = _controllerConf.getDefaultTableMinReplicas();
if (requestReplication < configMinReplication) {
LOGGER.info("Creating table with minimum replication factor of: {} instead of requested replication: {}", configMinReplication, requestReplication);
segmentsConfig.setReplication(String.valueOf(configMinReplication));
}
if (segmentsConfig.getReplicasPerPartition() != null) {
int replicasPerPartition = Integer.valueOf(segmentsConfig.getReplicasPerPartition());
if (replicasPerPartition < configMinReplication) {
LOGGER.info("Creating table with minimum replicasPerPartition of: {} instead of requested replicasPerPartition: {}", configMinReplication, requestReplication);
segmentsConfig.setReplicasPerPartition(String.valueOf(configMinReplication));
}
}
_pinotHelixResourceManager.addTable(config);
}
Aggregations