Search in sources :

Example 1 with Paths

use of com.linkedin.pinot.common.restlet.swagger.Paths in project pinot by linkedin.

the class PinotRestletApplication method attachRoutesForClass.

protected void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
    TreeSet<String> pathsOrderedByLength = new TreeSet<String>(ComparatorUtils.chainedComparator(new Comparator<String>() {

        @Override
        public int compare(String left, String right) {
            int leftLength = left.length();
            int rightLength = right.length();
            return leftLength < rightLength ? -1 : (leftLength == rightLength ? 0 : 1);
        }
    }, ComparatorUtils.NATURAL_COMPARATOR));
    for (Method method : clazz.getDeclaredMethods()) {
        Annotation annotationInstance = method.getAnnotation(Paths.class);
        if (annotationInstance != null) {
            pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
        }
    }
    for (String routePath : pathsOrderedByLength) {
        LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
        attachRoute(router, routePath, clazz);
    }
}
Also used : TreeSet(java.util.TreeSet) Method(java.lang.reflect.Method) Paths(com.linkedin.pinot.common.restlet.swagger.Paths) Annotation(java.lang.annotation.Annotation) Comparator(java.util.Comparator)

Example 2 with Paths

use of com.linkedin.pinot.common.restlet.swagger.Paths in project pinot by linkedin.

the class PinotSegmentRestletResource method getAllSegmentsMetadataForTable.

@HttpVerb("get")
@Summary("Lists segment metadata for a given table")
@Tags({ "segment", "table" })
@Paths({ "/tables/{tableName}/segments/metadata", "/tables/{tableName}/segments/metadata/" })
@Responses({ @Response(statusCode = "200", description = "A list of segment metadata"), @Response(statusCode = "404", description = "The table does not exist") })
private Representation getAllSegmentsMetadataForTable(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to list segment metadata", required = true) String tableName, @Parameter(name = "type", in = "query", description = "Type of table {offline|realtime}", required = false) String tableType) throws JSONException, JsonProcessingException {
    boolean foundRealtimeTable = false;
    boolean foundOfflineTable = false;
    JSONArray ret = new JSONArray();
    if ((tableType == null || TableType.REALTIME.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
        String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
        JSONObject realtime = new JSONObject();
        realtime.put(TABLE_NAME, realtimeTableName);
        realtime.put("segments", new ObjectMapper().writeValueAsString(_pinotHelixResourceManager.getInstanceToSegmentsInATableMap(realtimeTableName)));
        ret.put(realtime);
        foundRealtimeTable = true;
    }
    if ((tableType == null || TableType.OFFLINE.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
        String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
        JSONObject offline = new JSONObject();
        offline.put(TABLE_NAME, offlineTableName);
        offline.put("segments", new ObjectMapper().writeValueAsString(_pinotHelixResourceManager.getInstanceToSegmentsInATableMap(offlineTableName)));
        ret.put(offline);
        foundOfflineTable = true;
    }
    if (foundOfflineTable || foundRealtimeTable) {
        return new StringRepresentation(ret.toString());
    } else {
        setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        return new StringRepresentation("Table " + tableName + " not found.");
    }
}
Also used : JSONObject(org.json.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(org.json.JSONArray) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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 3 with Paths

use of com.linkedin.pinot.common.restlet.swagger.Paths in project pinot by linkedin.

the class PinotSegmentRestletResource method getSegmentMetadataForTable.

@HttpVerb("get")
@Summary("Gets segment metadata for a given segment")
@Tags({ "segment", "table" })
@Paths({ "/tables/{tableName}/segments/{segmentName}/metadata", "/tables/{tableName}/segments/{segmentName}/metadata/" })
private Representation getSegmentMetadataForTable(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to list segment metadata", required = true) String tableName, @Parameter(name = "segmentName", in = "path", description = "The name of the segment for which to fetch metadata", required = true) String segmentName, @Parameter(name = "type", in = "query", description = "Type of table {offline|realtime}", required = false) String tableType) throws JsonProcessingException, JSONException {
    JSONArray ret = new JSONArray();
    if ((tableType == null || TableType.OFFLINE.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
        String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
        ret.put(getSegmentMetaData(offlineTableName, segmentName, TableType.OFFLINE));
    }
    if ((tableType == null || TableType.REALTIME.name().equalsIgnoreCase(tableType)) && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
        String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
        ret.put(getSegmentMetaData(realtimeTableName, segmentName, TableType.REALTIME));
    }
    return new StringRepresentation(ret.toString());
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(org.json.JSONArray) 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)

Example 4 with Paths

use of com.linkedin.pinot.common.restlet.swagger.Paths 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 5 with Paths

use of com.linkedin.pinot.common.restlet.swagger.Paths 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)

Aggregations

Paths (com.linkedin.pinot.common.restlet.swagger.Paths)33 HttpVerb (com.linkedin.pinot.common.restlet.swagger.HttpVerb)32 Summary (com.linkedin.pinot.common.restlet.swagger.Summary)32 Tags (com.linkedin.pinot.common.restlet.swagger.Tags)31 StringRepresentation (org.restlet.representation.StringRepresentation)30 Responses (com.linkedin.pinot.common.restlet.swagger.Responses)14 JSONObject (org.json.JSONObject)10 JSONArray (org.json.JSONArray)9 AbstractTableConfig (com.linkedin.pinot.common.config.AbstractTableConfig)7 Schema (com.linkedin.pinot.common.data.Schema)5 PinotResourceManagerResponse (com.linkedin.pinot.controller.helix.core.PinotResourceManagerResponse)5 File (java.io.File)5 IOException (java.io.IOException)4 JSONException (org.json.JSONException)4 FileRepresentation (org.restlet.representation.FileRepresentation)3 Representation (org.restlet.representation.Representation)3 Description (com.linkedin.pinot.common.restlet.swagger.Description)2 TreeSet (java.util.TreeSet)2 JSONArray (com.alibaba.fastjson.JSONArray)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1