Search in sources :

Example 6 with Paths

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

the class PinotSchemaRestletResource method deleteSchema.

@HttpVerb("delete")
@Summary("Deletes a schema")
@Tags({ "schema" })
@Paths({ "/schemas/{schemaName}", "/schemas/{schemaName}/" })
@Responses({ @Response(statusCode = "200", description = "The schema was deleted"), @Response(statusCode = "404", description = "The schema does not exist"), @Response(statusCode = "409", description = "The schema could not be deleted due to being in use"), @Response(statusCode = "500", description = "There was an error while deleting the schema") })
StringRepresentation deleteSchema(@Parameter(name = "schemaName", in = "path", description = "The name of the schema to get", required = true) String schemaName) throws JSONException, IOException {
    Schema schema = _pinotHelixResourceManager.getSchema(schemaName);
    if (schema == null) {
        LOGGER.error("Error: could not find schema {}", schemaName);
        setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        return new StringRepresentation("Error: Could not find schema " + schemaName);
    }
    // If the schema is associated with a table, we should not delete it.
    List<String> tableNames = _pinotHelixResourceManager.getAllRealtimeTables();
    for (String tableName : tableNames) {
        AbstractTableConfig config = _pinotHelixResourceManager.getTableConfig(tableName, CommonConstants.Helix.TableType.REALTIME);
        String tableSchema = config.getValidationConfig().getSchemaName();
        if (schemaName.equals(tableSchema)) {
            LOGGER.error("Cannot delete schema {}, as it is associated with table {}", schemaName, tableName);
            setStatus(Status.CLIENT_ERROR_CONFLICT);
            return new StringRepresentation("Error: Cannot delete schema " + schemaName + " as it is associated with table: " + TableNameBuilder.extractRawTableName(tableName));
        }
    }
    LOGGER.info("Trying to delete schema {}", schemaName);
    if (_pinotHelixResourceManager.deleteSchema(schema)) {
        LOGGER.info("Success: Deleted schema {}", schemaName);
        setStatus(Status.SUCCESS_OK);
        return new StringRepresentation("Success: Deleted schema " + schemaName);
    } else {
        LOGGER.error("Error: could not delete schema {}", schemaName);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_DELETE_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
        return new StringRepresentation("Error: Could not delete schema " + schemaName);
    }
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) Schema(com.linkedin.pinot.common.data.Schema) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) 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 Paths

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

the class PinotSchemaRestletResource method uploadSchema.

@HttpVerb("put")
@Summary("Updates an existing schema")
@Tags({ "schema" })
@Paths({ "/schemas/{schemaName}", "/schemas/{schemaName}/" })
@Responses({ @Response(statusCode = "200", description = "The schema was updated"), @Response(statusCode = "500", description = "There was an error while updating the schema") })
private Representation uploadSchema(@Parameter(name = "schemaName", in = "path", description = "The name of the schema to get") String schemaName) throws Exception {
    File dataFile = getUploadContents();
    if (dataFile != null) {
        Schema schema = Schema.fromFile(dataFile);
        try {
            if (schema.getSchemaName().equals(schemaName)) {
                _pinotHelixResourceManager.addOrUpdateSchema(schema);
                return new StringRepresentation(dataFile + " sucessfully added", MediaType.TEXT_PLAIN);
            } else {
                final String message = "Schema name mismatch for uploaded schema, tried to add schema with name " + schema.getSchemaName() + " as " + schemaName;
                LOGGER.warn(message);
                ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
                setStatus(Status.SERVER_ERROR_INTERNAL);
                return new StringRepresentation(message, MediaType.TEXT_PLAIN);
            }
        } catch (Exception e) {
            LOGGER.error("error adding schema ", e);
            LOGGER.error("Caught exception in file upload", e);
            ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
            setStatus(Status.SERVER_ERROR_INTERNAL);
            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)

Example 8 with Paths

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

the class PinotTableInstances method getTableInstances.

@HttpVerb("get")
@Summary("Lists table instances for a given table")
@Tags({ "instance", "table" })
@Paths({ "/tables/{tableName}/instances" })
private Representation getTableInstances(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to list instances", required = true) String tableName, String type) throws JSONException, IOException {
    JSONObject ret = new JSONObject();
    ret.put("tableName", tableName);
    JSONArray brokers = new JSONArray();
    JSONArray servers = new JSONArray();
    if (type == null || type.toLowerCase().equals("broker")) {
        if (_pinotHelixResourceManager.hasOfflineTable(tableName)) {
            JSONObject e = new JSONObject();
            e.put("tableType", "offline");
            JSONArray a = new JSONArray();
            for (String ins : _pinotHelixResourceManager.getBrokerInstancesForTable(tableName, TableType.OFFLINE)) {
                a.add(ins);
            }
            e.put("instances", a);
            brokers.add(e);
        }
        if (_pinotHelixResourceManager.hasRealtimeTable(tableName)) {
            JSONObject e = new JSONObject();
            e.put("tableType", "realtime");
            JSONArray a = new JSONArray();
            for (String ins : _pinotHelixResourceManager.getBrokerInstancesForTable(tableName, TableType.REALTIME)) {
                a.add(ins);
            }
            e.put("instances", a);
            brokers.add(e);
        }
    }
    if (type == null || type.toLowerCase().equals("server")) {
        if (_pinotHelixResourceManager.hasOfflineTable(tableName)) {
            JSONObject e = new JSONObject();
            e.put("tableType", "offline");
            JSONArray a = new JSONArray();
            for (String ins : _pinotHelixResourceManager.getServerInstancesForTable(tableName, TableType.OFFLINE)) {
                a.add(ins);
            }
            e.put("instances", a);
            servers.add(e);
        }
        if (_pinotHelixResourceManager.hasRealtimeTable(tableName)) {
            JSONObject e = new JSONObject();
            e.put("tableType", "realtime");
            JSONArray a = new JSONArray();
            for (String ins : _pinotHelixResourceManager.getServerInstancesForTable(tableName, TableType.REALTIME)) {
                a.add(ins);
            }
            e.put("instances", a);
            servers.add(e);
        }
    }
    ret.put("brokers", brokers);
    ret.put("server", servers);
    return new StringRepresentation(ret.toString());
}
Also used : JSONObject(org.json.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation) JSONArray(com.alibaba.fastjson.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 9 with Paths

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

the class PinotTableMetadataConfigs method updateTableMetadata.

@Deprecated
@HttpVerb("put")
@Summary("DEPRECATED: Updates the metadata configuration for a table")
@Tags({ "table" })
@Paths({ "/tables/{tableName}/metadataConfigs" })
private Representation updateTableMetadata(@Parameter(name = "tableName", in = "path", description = "The name of the table for which to update the metadata configuration", required = true) String tableName, Representation entity) throws Exception {
    AbstractTableConfig config = AbstractTableConfig.init(entity.getText());
    _pinotHelixResourceManager.updateMetadataConfigFor(config.getTableName(), TableType.valueOf(config.getTableType().toUpperCase()), config.getCustomConfigs());
    return new StringRepresentation("done");
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) 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 10 with Paths

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

the class PinotTableRestletResource method updateTableConfig.

/*
   * NOTE: There is inconsistency in these APIs. GET returns OFFLINE + REALTIME configuration
   * in a single response but POST and this PUT request only operate on either offline or realtime
   * table configuration. If we make this API take both realtime and offline table configuration
   * then the update is not guaranteed to be transactional for both table types. This is more of a PATCH request
   * than PUT.
   */
@HttpVerb("put")
@Summary("Update table configuration. Request body is offline or realtime table configuration")
@Tags({ "Table" })
@Paths({ "/tables/{tableName}" })
public Representation updateTableConfig(@Parameter(name = "tableName", in = "path", description = "Table name (without type)") String tableName, Representation entity) {
    AbstractTableConfig config = null;
    try {
        config = AbstractTableConfig.init(entity.getText());
    } catch (JSONException e) {
        errorResponseRepresentation(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid json in table configuration");
    } catch (IOException e) {
        LOGGER.error("Failed to read request body while updating configuration for table: {}", tableName, e);
        errorResponseRepresentation(Status.SERVER_ERROR_INTERNAL, "Failed to read request");
    }
    try {
        String tableTypeStr = config.getTableType();
        TableType tableType = TableType.valueOf(tableTypeStr.toUpperCase());
        String configTableName = config.getTableName();
        if (!configTableName.equals(tableName)) {
            errorResponseRepresentation(Status.CLIENT_ERROR_BAD_REQUEST, "Request table name does not match table name in the body");
        }
        String tableNameWithType = null;
        if (config.getTableType().equalsIgnoreCase(TableType.OFFLINE.name())) {
            tableNameWithType = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
        } else if (config.getTableType().equalsIgnoreCase(TableType.REALTIME.name())) {
            tableNameWithType = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
        }
        _pinotHelixResourceManager.setTableConfig(config, tableNameWithType, tableType);
        return responseRepresentation(Status.SUCCESS_OK, "{\"status\" : \"Success\"}");
    } catch (IOException e) {
        LOGGER.error("Failed to update table configuration for table: {}", tableName, e);
        return errorResponseRepresentation(Status.SERVER_ERROR_INTERNAL, "Internal error while updating table configuration");
    }
}
Also used : TableType(com.linkedin.pinot.common.utils.CommonConstants.Helix.TableType) JSONException(org.json.JSONException) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) 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)

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