use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTableRestletResource method setTablestate.
@HttpVerb("get")
@Summary("Enable, disable or drop a table")
@Tags({ "table" })
@Paths({ "/tables/{tableName}", "/table/{tableName}/" })
private StringRepresentation setTablestate(@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 = false) String type, @Parameter(name = "state", in = "query", description = "The desired table state, either enable or disable", required = true) String state) throws JSONException {
JSONArray ret = new JSONArray();
boolean tableExists = false;
if ((type == null || TableType.OFFLINE.name().equalsIgnoreCase(type)) && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
JSONObject offline = new JSONObject();
tableExists = true;
offline.put(TABLE_NAME, offlineTableName);
offline.put(STATE, toggleTableState(offlineTableName, state).toJSON().toString());
ret.put(offline);
}
if ((type == null || TableType.REALTIME.name().equalsIgnoreCase(type)) && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
String realTimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
JSONObject realTime = new JSONObject();
tableExists = true;
realTime.put(TABLE_NAME, realTimeTableName);
realTime.put(STATE, toggleTableState(realTimeTableName, state).toJSON().toString());
ret.put(realTime);
}
if (tableExists) {
return new StringRepresentation(ret.toString());
} else {
setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation("Error: Table " + tableName + " not found.");
}
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTableRestletResource method getAllTables.
@HttpVerb("get")
@Summary("Views all tables' configuration")
@Tags({ "table" })
@Paths({ "/tables", "/tables/" })
private Representation getAllTables() throws JSONException {
JSONObject object = new JSONObject();
JSONArray tableArray = new JSONArray();
Set<String> tableNames = new TreeSet<String>();
tableNames.addAll(_pinotHelixResourceManager.getAllUniquePinotRawTableNames());
for (String pinotTableName : tableNames) {
tableArray.put(pinotTableName);
}
object.put("tables", tableArray);
return new StringRepresentation(object.toString(2));
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTableRestletResource method delete.
@Override
@Delete
public Representation delete() {
StringRepresentation presentation = null;
final String tableName = (String) getRequest().getAttributes().get(TABLE_NAME);
final String type = getReference().getQueryAsForm().getValues(TABLE_TYPE);
if (!deleteTable(tableName, type)) {
String error = new String("Error: Table " + tableName + " not found.");
LOGGER.error(error);
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation(error);
}
return presentation;
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTableRestletResource method post.
@Override
@Post("json")
public Representation post(Representation entity) {
AbstractTableConfig config = null;
try {
String jsonRequest = entity.getText();
config = AbstractTableConfig.init(jsonRequest);
try {
addTable(config);
} catch (Exception e) {
LOGGER.error("Caught exception while adding table", e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_ADD_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Failed: " + e.getMessage());
}
return new StringRepresentation("Success");
} catch (Exception e) {
LOGGER.error("error reading/serializing requestJSON", e);
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Failed: " + e.getMessage());
}
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTableSchema method getTableSchema.
@HttpVerb("get")
@Summary("Gets schema for a table")
@Tags({ "schema", "table" })
@Paths({ "/tables/{tableName}/schema", "/tables/{tableName}/schema/" })
private Representation getTableSchema(@Parameter(name = "tableName", in = "path", description = "Table name for which to get the schema", required = true) String tableName) {
if (_pinotHelixResourceManager.hasRealtimeTable(tableName)) {
try {
AbstractTableConfig config = _pinotHelixResourceManager.getTableConfig(tableName, TableType.REALTIME);
return new StringRepresentation(_pinotHelixResourceManager.getSchema(config.getValidationConfig().getSchemaName()).getJSONSchema().toString());
} catch (Exception e) {
LOGGER.error("Caught exception while fetching schema for a realtime table : {} ", tableName, e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_SCHEMA_GET_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
return PinotSegmentUploadRestletResource.exceptionToStringRepresentation(e);
}
} else {
AbstractTableConfig config;
try {
config = _pinotHelixResourceManager.getTableConfig(tableName, TableType.OFFLINE);
String schemaName = config.getValidationConfig().getSchemaName();
Schema schema = null;
if (schemaName != null && !schemaName.isEmpty()) {
schema = _pinotHelixResourceManager.getSchema(schemaName);
}
if (schema == null) {
setStatus(Status.CLIENT_ERROR_NOT_FOUND);
StringRepresentation repr = new StringRepresentation("{\"error\": \"Schema " + schemaName + " not found\"");
repr.setMediaType(MediaType.APPLICATION_JSON);
return repr;
}
return new StringRepresentation(schema.getJSONSchema().toString());
} catch (Exception e) {
LOGGER.error("Caught exception while fetching schema for a offline table : {} ", tableName, e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_SCHEMA_GET_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
return PinotSegmentUploadRestletResource.exceptionToStringRepresentation(e);
}
}
}
Aggregations