Search in sources :

Example 11 with PluginException

use of org.apache.drill.exec.store.StoragePluginRegistry.PluginException in project drill by apache.

the class StorageResources method deletePlugin.

@DELETE
@Path("/storage/{name}.json")
@Produces(MediaType.APPLICATION_JSON)
public Response deletePlugin(@PathParam("name") String name) {
    try {
        TokenRegistry tokenRegistry = ((AbstractStoragePlugin) storage.getPlugin(name)).getContext().getoAuthTokenProvider().getOauthTokenRegistry();
        // Delete a token registry table if it exists
        tokenRegistry.deleteTokenTable(name);
        storage.remove(name);
        return Response.ok().entity(message("Success")).build();
    } catch (PluginException e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message("Error while deleting plugin: %s", e.getMessage())).build();
    }
}
Also used : TokenRegistry(org.apache.drill.exec.oauth.TokenRegistry) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) AbstractStoragePlugin(org.apache.drill.exec.store.AbstractStoragePlugin) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 12 with PluginException

use of org.apache.drill.exec.store.StoragePluginRegistry.PluginException in project drill by apache.

the class DescribeSchemaHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
    SqlIdentifier schema = unwrap(sqlNode, SqlDescribeSchema.class).getSchema();
    SchemaPlus schemaPlus = SchemaUtilites.findSchema(config.getConverter().getDefaultSchema(), schema.names);
    if (schemaPlus == null) {
        throw UserException.validationError().message("Invalid schema name [%s]", Joiner.on(".").join(schema.names)).build(logger);
    }
    AbstractSchema drillSchema = SchemaUtilites.unwrapAsDrillSchemaInstance(schemaPlus);
    StoragePlugin storagePlugin;
    try {
        storagePlugin = context.getStorage().getPlugin(drillSchema.getSchemaPath().get(0));
        if (storagePlugin == null) {
            throw new DrillRuntimeException(String.format("Unable to find storage plugin with the following name [%s].", drillSchema.getSchemaPath().get(0)));
        }
    } catch (PluginException e) {
        throw new DrillRuntimeException("Failure while retrieving storage plugin", e);
    }
    try {
        Map configMap = mapper.convertValue(storagePlugin.getConfig(), Map.class);
        if (storagePlugin instanceof FileSystemPlugin) {
            transformWorkspaces(drillSchema.getSchemaPath(), configMap);
        }
        String properties = mapper.writeValueAsString(configMap);
        return DirectPlan.createDirectPlan(context, new DescribeSchemaResult(drillSchema.getFullSchemaName(), properties));
    } catch (JsonProcessingException e) {
        throw new DrillRuntimeException("Error while trying to convert storage config to json string", e);
    }
}
Also used : FileSystemPlugin(org.apache.drill.exec.store.dfs.FileSystemPlugin) AbstractSchema(org.apache.drill.exec.store.AbstractSchema) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SerializableString(com.fasterxml.jackson.core.SerializableString) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SqlDescribeSchema(org.apache.calcite.sql.SqlDescribeSchema) StoragePlugin(org.apache.drill.exec.store.StoragePlugin)

Aggregations

PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)12 BaseTest (org.apache.drill.test.BaseTest)5 ClusterFixture (org.apache.drill.test.ClusterFixture)5 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)5 Test (org.junit.Test)5 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)3 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)3 FileSystemPlugin (org.apache.drill.exec.store.dfs.FileSystemPlugin)3 IOException (java.io.IOException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 SchemaPlus (org.apache.calcite.schema.SchemaPlus)2 UserException (org.apache.drill.common.exceptions.UserException)2 TokenRegistry (org.apache.drill.exec.oauth.TokenRegistry)2 Drillbit (org.apache.drill.exec.server.Drillbit)2 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)2 AbstractStoragePlugin (org.apache.drill.exec.store.AbstractStoragePlugin)2 StoragePlugin (org.apache.drill.exec.store.StoragePlugin)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SerializableString (com.fasterxml.jackson.core.SerializableString)1