Search in sources :

Example 6 with Responses

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

the class PinotSegmentUploadRestletResource method getAllSegments.

@HttpVerb("get")
@Summary("Lists all segments")
@Tags({ "segment" })
@Paths({ "/segments", "/segments/" })
@Responses({ @Response(statusCode = "200", description = "A list of all segments for the all tables") })
private Representation getAllSegments() {
    Representation presentation;
    final JSONArray ret = new JSONArray();
    for (final File file : baseDataDir.listFiles()) {
        final String fileName = file.getName();
        if (fileName.equalsIgnoreCase("fileUploadTemp") || fileName.equalsIgnoreCase("schemasTemp")) {
            continue;
        }
        final String url = _controllerConf.generateVipUrl() + "/segments/" + fileName;
        ret.put(url);
    }
    presentation = new StringRepresentation(ret.toString());
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(org.json.JSONArray) 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 7 with Responses

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

the class PinotSegmentUploadRestletResource method getSegmentsForTable.

@HttpVerb("get")
@Summary("Lists all segments for a given table")
@Tags({ "segment", "table" })
@Paths({ "/segments/{tableName}", "/segments/{tableName}/" })
@Responses({ @Response(statusCode = "200", description = "A list of all segments for the specified table"), @Response(statusCode = "404", description = "The segment file or table does not exist") })
private Representation getSegmentsForTable(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to list segments", required = true) String tableName, @Parameter(name = "tableType", in = "query", description = "Type of table {offline|realtime}", required = false) String type) throws Exception {
    Representation presentation;
    JSONArray ret = new JSONArray();
    final String realtime = "REALTIME";
    final String offline = "OFFLINE";
    if (type == null) {
        ret.put(formatSegments(tableName, CommonConstants.Helix.TableType.valueOf(offline)));
        ret.put(formatSegments(tableName, CommonConstants.Helix.TableType.valueOf(realtime)));
    } else {
        ret.put(formatSegments(tableName, CommonConstants.Helix.TableType.valueOf(type)));
    }
    presentation = new StringRepresentation(ret.toString());
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(org.json.JSONArray) StringRepresentation(org.restlet.representation.StringRepresentation) FileRepresentation(org.restlet.representation.FileRepresentation) Representation(org.restlet.representation.Representation) 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 Responses

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

the class PinotInstanceRestletResource method getInstanceInformation.

/**
   * Gets the information for an instance.
   *
   * @param instanceName The instance name
   */
@HttpVerb("get")
@Summary("Gets information for an instance")
@Tags({ "instance" })
@Paths({ "/instances/{instanceName}", "/instances/{instanceName}/" })
@Responses({ @Response(statusCode = "200", description = "Information about the specified instance"), @Response(statusCode = "404", description = "The specified instance does not exist"), @Response(statusCode = "500", description = "There was an error while fetching information for the given instance") })
private Representation getInstanceInformation(@Parameter(name = "instanceName", description = "The name of the instance (eg. Server_1.2.3.4_1234 or Broker_someHost.example.com_2345)", in = "path", required = true) String instanceName) {
    try {
        if (!_pinotHelixResourceManager.instanceExists(instanceName)) {
            setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return new StringRepresentation("Error: Instance " + instanceName + " not found.");
        }
        InstanceConfig instanceConfig = _pinotHelixResourceManager.getHelixInstanceConfig(instanceName);
        JSONObject response = new JSONObject();
        response.put("instanceName", instanceConfig.getInstanceName());
        response.put("hostName", instanceConfig.getHostName());
        response.put("enabled", instanceConfig.getInstanceEnabled());
        response.put("port", instanceConfig.getPort());
        response.put("tags", new JSONArray(instanceConfig.getTags()));
        return new StringRepresentation(response.toString());
    } catch (Exception e) {
        LOGGER.warn("Caught exception while fetching information for instance {}", instanceName, e);
        setStatus(Status.SERVER_ERROR_INTERNAL);
        return new StringRepresentation("{}");
    }
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) JSONObject(org.json.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) 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 9 with Responses

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

the class PinotInstanceRestletResource method addInstance.

@HttpVerb("post")
@Summary("Adds an instance")
@Tags({ "instance" })
@Paths({ "/instances", "/instances/" })
@Responses({ @Response(statusCode = "200", description = "The instance was created successfully"), @Response(statusCode = "409", description = "The instance already exists and no action was taken"), @Response(statusCode = "500", description = "Failed to create the instance") })
private StringRepresentation addInstance(@Parameter(name = "instance", in = "body", description = "The instance to add", required = true) Instance instance) throws JSONException {
    StringRepresentation presentation;
    LOGGER.info("Instance creation request received for instance " + instance.toInstanceId());
    final PinotResourceManagerResponse resp = _pinotHelixResourceManager.addInstance(instance);
    if (resp.status == PinotResourceManagerResponse.ResponseStatus.failure) {
        setStatus(Status.CLIENT_ERROR_CONFLICT);
    }
    presentation = new StringRepresentation(resp.toJSON().toString());
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) PinotResourceManagerResponse(com.linkedin.pinot.controller.helix.core.PinotResourceManagerResponse) 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 10 with Responses

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

the class PinotInstanceRestletResource method toggleInstanceState.

/**
   *
   * @param instanceName: Name of the instance to enable/disable/drop
   * @param state: One of '{enable|disable|drop}'
   * @return StringRepresentation of state after trying to enable/disable/drop instance.
   * @throws JSONException
   */
@HttpVerb("post")
@Summary("Enable, disable or drop an instance")
@Tags({ "instance" })
@Paths({ "/instances/{instanceName}/state", "/instances/{instanceName}/state" })
@Responses({ @Response(statusCode = "200", description = "The instance state was changed successfully"), @Response(statusCode = "400", description = "The state given was not enable, disable or drop"), @Response(statusCode = "404", description = "The instance was not found") })
private StringRepresentation toggleInstanceState(@Parameter(name = "instanceName", in = "path", description = "The name of the instance for which to toggle its state", required = true) String instanceName, @Parameter(name = "state", in = "body", description = "The desired instance state, either enable, disable or drop", required = true) String state) throws JSONException {
    if (StateType.ENABLE.name().equalsIgnoreCase(state)) {
        return new StringRepresentation(_pinotHelixResourceManager.enableInstance(instanceName).toJSON().toString());
    } else if (StateType.DISABLE.name().equalsIgnoreCase(state)) {
        return new StringRepresentation(_pinotHelixResourceManager.disableInstance(instanceName).toJSON().toString());
    } else if (StateType.DROP.name().equalsIgnoreCase(state)) {
        return new StringRepresentation(_pinotHelixResourceManager.dropInstance(instanceName).toJSON().toString());
    } else {
        LOGGER.error(INVALID_INSTANCE_URI_ERROR);
        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation(INVALID_INSTANCE_URI_ERROR);
    }
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) 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)

Aggregations

HttpVerb (com.linkedin.pinot.common.restlet.swagger.HttpVerb)14 Paths (com.linkedin.pinot.common.restlet.swagger.Paths)14 Responses (com.linkedin.pinot.common.restlet.swagger.Responses)14 Summary (com.linkedin.pinot.common.restlet.swagger.Summary)14 Tags (com.linkedin.pinot.common.restlet.swagger.Tags)14 StringRepresentation (org.restlet.representation.StringRepresentation)14 JSONArray (org.json.JSONArray)6 File (java.io.File)5 Schema (com.linkedin.pinot.common.data.Schema)4 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 FileRepresentation (org.restlet.representation.FileRepresentation)3 Representation (org.restlet.representation.Representation)3 PinotResourceManagerResponse (com.linkedin.pinot.controller.helix.core.PinotResourceManagerResponse)2 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AbstractTableConfig (com.linkedin.pinot.common.config.AbstractTableConfig)1 OfflineTableConfig (com.linkedin.pinot.common.config.OfflineTableConfig)1 SegmentMetadata (com.linkedin.pinot.common.segment.SegmentMetadata)1 StorageQuotaChecker (com.linkedin.pinot.controller.validation.StorageQuotaChecker)1