Search in sources :

Example 11 with Responses

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

the class PinotInstanceRestletResource method getAllInstances.

/**
   * Get all instances in the cluster
   * @return List of all instances in the cluster.
   * @throws JSONException
   */
@HttpVerb("get")
@Summary("Views all instances")
@Tags({ "instance" })
@Paths({ "/instances", "/instances/" })
@Responses({ @Response(statusCode = "200", description = "A list of instances") })
private Representation getAllInstances() throws JSONException {
    JSONObject object = new JSONObject();
    JSONArray instanceArray = new JSONArray();
    List<String> instanceNames = _pinotHelixResourceManager.getAllInstanceNames();
    for (String instanceName : instanceNames) {
        instanceArray.put(instanceName);
    }
    object.put("instances", instanceArray);
    return new StringRepresentation(object.toString());
}
Also used : JSONObject(org.json.JSONObject) 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) Responses(com.linkedin.pinot.common.restlet.swagger.Responses)

Example 12 with Responses

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

the class PinotSchemaRestletResource method getSchema.

@HttpVerb("get")
@Summary("Gets a schema")
@Tags({ "schema" })
@Paths({ "/schemas/{schemaName}", "/schemas/{schemaName}/" })
@Responses({ @Response(statusCode = "200", description = "The contents of the specified schema"), @Response(statusCode = "404", description = "The specified schema does not exist") })
private Representation getSchema(@Parameter(name = "schemaName", in = "path", description = "The name of the schema to get") String schemaName) throws IOException {
    LOGGER.info("looking for schema {}", schemaName);
    Schema schema = _pinotHelixResourceManager.getSchema(schemaName);
    if (schema == null) {
        setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        return new StringRepresentation("{}");
    }
    LOGGER.info("schema string is : " + schema.getJSONSchema());
    return new StringRepresentation(schema.getJSONSchema());
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) Schema(com.linkedin.pinot.common.data.Schema) 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 13 with Responses

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

the class PinotSchemaRestletResource method getAllSchemas.

@HttpVerb("get")
@Summary("Get a list of all schemas")
@Tags({ "schema" })
@Paths({ "/schemas", "/schemas/" })
@Responses({ @Response(statusCode = "200", description = "A list of all schemas") })
private Representation getAllSchemas() {
    List<String> schemaNames = _pinotHelixResourceManager.getSchemaNames();
    JSONArray ret = new JSONArray();
    if (schemaNames == null) {
        return new StringRepresentation(ret.toString());
    }
    for (String schema : schemaNames) {
        ret.put(schema);
    }
    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) Responses(com.linkedin.pinot.common.restlet.swagger.Responses)

Example 14 with Responses

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

the class PinotSchemaRestletResource method uploadNewSchema.

@HttpVerb("post")
@Summary("Adds a new schema")
@Tags({ "schema" })
@Paths({ "/schemas", "/schemas/" })
@Responses({ @Response(statusCode = "200", description = "The schema was added"), @Response(statusCode = "500", description = "There was an error while adding the schema") })
private Representation uploadNewSchema() throws Exception {
    File dataFile = getUploadContents();
    if (dataFile != null) {
        Schema schema = Schema.fromFile(dataFile);
        try {
            if (!schema.validate(LOGGER)) {
                throw new RuntimeException("Schema validation failed");
            }
            _pinotHelixResourceManager.addOrUpdateSchema(schema);
            return new StringRepresentation(dataFile + " sucessfully added", MediaType.TEXT_PLAIN);
        } catch (Exception e) {
            LOGGER.error("error adding schema ", e);
            LOGGER.error("Caught exception in file upload", e);
            setStatus(Status.SERVER_ERROR_INTERNAL);
            ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
            return PinotSegmentUploadRestletResource.exceptionToStringRepresentation(e);
        }
    } else {
        // Some problem occurs, send back a simple line of text.
        LOGGER.warn("No file was uploaded");
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
        return new StringRepresentation("schema not added", MediaType.TEXT_PLAIN);
    }
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) Schema(com.linkedin.pinot.common.data.Schema) File(java.io.File) JSONException(org.json.JSONException) IOException(java.io.IOException) 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