Search in sources :

Example 6 with StringRepresentation

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;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Get(org.restlet.resource.Get)

Example 7 with StringRepresentation

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;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) FileRepresentation(org.restlet.representation.FileRepresentation) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringRepresentation(org.restlet.representation.StringRepresentation) FileRepresentation(org.restlet.representation.FileRepresentation) Representation(org.restlet.representation.Representation) File(java.io.File) Summary(com.linkedin.pinot.common.restlet.swagger.Summary) HttpVerb(com.linkedin.pinot.common.restlet.swagger.HttpVerb) Paths(com.linkedin.pinot.common.restlet.swagger.Paths) Tags(com.linkedin.pinot.common.restlet.swagger.Tags) Responses(com.linkedin.pinot.common.restlet.swagger.Responses)

Example 8 with StringRepresentation

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);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation)

Example 9 with StringRepresentation

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());
}
Also used : SegmentCompletionProtocol(com.linkedin.pinot.common.protocols.SegmentCompletionProtocol) StringRepresentation(org.restlet.representation.StringRepresentation) SegmentCompletionManager(com.linkedin.pinot.controller.helix.core.realtime.SegmentCompletionManager) Description(com.linkedin.pinot.common.restlet.swagger.Description) Summary(com.linkedin.pinot.common.restlet.swagger.Summary) HttpVerb(com.linkedin.pinot.common.restlet.swagger.HttpVerb) Paths(com.linkedin.pinot.common.restlet.swagger.Paths)

Example 10 with StringRepresentation

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;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) IOException(java.io.IOException) Delete(org.restlet.resource.Delete)

Aggregations

StringRepresentation (org.restlet.representation.StringRepresentation)130 HttpVerb (com.linkedin.pinot.common.restlet.swagger.HttpVerb)30 Paths (com.linkedin.pinot.common.restlet.swagger.Paths)30 Summary (com.linkedin.pinot.common.restlet.swagger.Summary)30 IOException (java.io.IOException)30 Tags (com.linkedin.pinot.common.restlet.swagger.Tags)29 ZkClient (org.apache.helix.manager.zk.ZkClient)29 JSONObject (org.json.JSONObject)23 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)19 ZNRecord (org.apache.helix.ZNRecord)17 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)17 JSONException (org.json.JSONException)17 Representation (org.restlet.representation.Representation)15 Responses (com.linkedin.pinot.common.restlet.swagger.Responses)14 HelixException (org.apache.helix.HelixException)12 JSONArray (org.json.JSONArray)12 Builder (org.apache.helix.PropertyKey.Builder)11 Get (org.restlet.resource.Get)10 Post (org.restlet.resource.Post)9 ResourceException (org.restlet.resource.ResourceException)9