use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotSegmentRestletResource method get.
/**
* URI Mappings:
* - "/tables/{tableName}/segments", "tables/{tableName}/segments/":
* List all segments in the table.
*
* - "/tables/{tableName}/segments/{segmentName}", "/tables/{tableName}/segments/{segmentName}/":
* List meta-data for the specified segment.
*
* - "/tables/{tableName}/segments/{segmentName}?state={state}",
* Change the state of the segment to specified {state} (enable|disable|drop)
*
* - "/tables/{tableName}/segments?state={state}"
* Change the state of all segments of the table to specified {state} (enable|disable|drop)
*
* {@inheritDoc}
* @see org.restlet.resource.ServerResource#get()
*/
@Override
@Get
public Representation get() {
StringRepresentation presentation = null;
try {
final String tableName = (String) getRequest().getAttributes().get(TABLE_NAME);
String segmentName = (String) getRequest().getAttributes().get(SEGMENT_NAME);
if (segmentName != null) {
segmentName = URLDecoder.decode(segmentName, "UTF-8");
}
final String state = getReference().getQueryAsForm().getValues(STATE);
final String tableType = getReference().getQueryAsForm().getValues(TABLE_TYPE);
if (tableType != null && !isValidTableType(tableType)) {
LOGGER.error(INVALID_TABLE_TYPE_ERROR);
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation(INVALID_TABLE_TYPE_ERROR);
}
if (state != null) {
if (!isValidState(state)) {
LOGGER.error(INVALID_STATE_ERROR);
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation(INVALID_STATE_ERROR);
} else {
if (segmentName != null) {
return toggleOneSegmentState(tableName, segmentName, state, tableType);
} else {
return toggleAllSegmentsState(tableName, state, tableType);
}
}
} else if (segmentName != null) {
return getSegmentMetadataForTable(tableName, segmentName, tableType);
} else {
return getAllSegmentsMetadataForTable(tableName, tableType);
}
} catch (final Exception e) {
presentation = new StringRepresentation(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
LOGGER.error("Caught exception while processing get request", e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SEGMENT_GET_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
}
return presentation;
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotSegmentUploadRestletResource method getSegmentFile.
@HttpVerb("get")
@Summary("Downloads a segment")
@Tags({ "segment", "table" })
@Paths({ "/segments/{tableName}/{segmentName}" })
@Responses({ @Response(statusCode = "200", description = "A segment file in Pinot format"), @Response(statusCode = "404", description = "The segment file or table does not exist") })
private Representation getSegmentFile(@Parameter(name = "tableName", in = "path", description = "The name of the table in which the segment resides", required = true) String tableName, @Parameter(name = "segmentName", in = "path", description = "The name of the segment to download", required = true) String segmentName) {
Representation presentation;
try {
segmentName = URLDecoder.decode(segmentName, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new AssertionError("UTF-8 encoding should always be supported", e);
}
final File dataFile = new File(baseDataDir, StringUtil.join("/", tableName, segmentName));
if (dataFile.exists()) {
presentation = new FileRepresentation(dataFile, MediaType.ALL, 0);
} else {
setStatus(Status.CLIENT_ERROR_NOT_FOUND);
presentation = new StringRepresentation("Table or segment is not found!");
}
return presentation;
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class BasePinotControllerRestletResource method exceptionToStringRepresentation.
public static StringRepresentation exceptionToStringRepresentation(Exception e) {
String errorMsg = e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e);
JSONObject errorMsgInJson = getErrorMsgInJson(errorMsg);
return new StringRepresentation(errorMsgInJson.toJSONString(), MediaType.APPLICATION_JSON);
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class LLCSegmentCommit method post.
@Override
@HttpVerb("post")
@Description("Uploads an LLC segment coming in from a server")
@Summary("Uploads an LLC segment coming in from a server")
@Paths({ "/" + SegmentCompletionProtocol.MSG_TYPE_COMMMIT })
public Representation post(Representation entity) {
if (!extractParams()) {
return new StringRepresentation(SegmentCompletionProtocol.RESP_FAILED.toJsonString());
}
LOGGER.info("segment={} offset={} instance={} ", _segmentNameStr, _offset, _instanceId);
final SegmentCompletionManager segmentCompletionManager = getSegmentCompletionManager();
final SegmentCompletionProtocol.Request.Params reqParams = new SegmentCompletionProtocol.Request.Params();
reqParams.withInstanceId(_instanceId).withSegmentName(_segmentNameStr).withOffset(_offset);
SegmentCompletionProtocol.Response response = segmentCompletionManager.segmentCommitStart(reqParams);
if (response.equals(SegmentCompletionProtocol.RESP_COMMIT_CONTINUE)) {
// Get the segment and put it in the right place.
boolean success = uploadSegment(_instanceId, _segmentNameStr);
response = segmentCompletionManager.segmentCommitEnd(reqParams, success);
}
LOGGER.info("Response: instance={} segment={} status={} offset={}", _instanceId, _segmentNameStr, response.getStatus(), response.getOffset());
return new StringRepresentation(response.toJsonString());
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotSchemaRestletResource method delete.
@Override
@Delete
public Representation delete() {
final String schemaName = (String) getRequest().getAttributes().get(SCHEMA_NAME);
if (schemaName == null) {
LOGGER.error("Error: Null schema name.");
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Error: Null schema name.");
}
StringRepresentation result = null;
try {
result = deleteSchema(schemaName);
} catch (Exception e) {
LOGGER.error("Caught exception while processing delete request", e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_DELETE_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
result = new StringRepresentation("Error: Caught Exception " + e.getStackTrace());
}
return result;
}
Aggregations