Search in sources :

Example 6 with UnsupportedTypeException

use of io.cdap.cdap.api.data.schema.UnsupportedTypeException in project cdap by caskdata.

the class ExploreExecutorHttpHandler method enableDataset.

private void enableDataset(HttpResponder responder, final DatasetId datasetId, final DatasetSpecification datasetSpec, final boolean truncating) {
    LOG.debug("Enabling explore for dataset instance {}", datasetId);
    try {
        QueryHandle handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {

            @Override
            public QueryHandle call() throws Exception {
                return exploreTableManager.enableDataset(datasetId, datasetSpec, truncating);
            }
        });
        JsonObject json = new JsonObject();
        json.addProperty("handle", handle.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json.toString());
    } catch (IllegalArgumentException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (ExploreException e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error enabling explore on dataset " + datasetId);
    } catch (SQLException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "SQL exception while trying to enable explore on dataset " + datasetId);
    } catch (UnsupportedTypeException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "Schema for dataset " + datasetId + " is not supported for exploration: " + e.getMessage());
    } catch (Throwable e) {
        LOG.error("Got exception:", e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) JsonObject(com.google.gson.JsonObject) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) QueryHandle(io.cdap.cdap.proto.QueryHandle) ExploreException(io.cdap.cdap.explore.service.ExploreException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) SQLException(java.sql.SQLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 7 with UnsupportedTypeException

use of io.cdap.cdap.api.data.schema.UnsupportedTypeException in project cdap by caskdata.

the class ExploreExecutorHttpHandler method updateDataset.

/**
 * Enable ad-hoc exploration of a dataset instance.
 */
@POST
@Path("datasets/{dataset}/update")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void updateDataset(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) throws BadRequestException {
    final DatasetId datasetId = new DatasetId(namespace, datasetName);
    try {
        UpdateExploreParameters params = readUpdateParameters(request);
        final DatasetSpecification oldSpec = params.getOldSpec();
        final DatasetSpecification datasetSpec = params.getNewSpec();
        QueryHandle handle;
        if (oldSpec.equals(datasetSpec)) {
            handle = QueryHandle.NO_OP;
        } else {
            handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {

                @Override
                public QueryHandle call() throws Exception {
                    return exploreTableManager.updateDataset(datasetId, datasetSpec, oldSpec);
                }
            });
        }
        JsonObject json = new JsonObject();
        json.addProperty("handle", handle.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json.toString());
    } catch (IllegalArgumentException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (ExploreException e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error updating explore on dataset " + datasetId);
    } catch (SQLException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "SQL exception while trying to update explore on dataset " + datasetId);
    } catch (UnsupportedTypeException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "Schema for dataset " + datasetId + " is not supported for exploration: " + e.getMessage());
    } catch (Throwable e) {
        LOG.error("Got exception:", e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : UpdateExploreParameters(io.cdap.cdap.explore.client.UpdateExploreParameters) SQLException(java.sql.SQLException) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) JsonObject(com.google.gson.JsonObject) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) QueryHandle(io.cdap.cdap.proto.QueryHandle) Callable(java.util.concurrent.Callable) DatasetId(io.cdap.cdap.proto.id.DatasetId) ExploreException(io.cdap.cdap.explore.service.ExploreException) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 8 with UnsupportedTypeException

use of io.cdap.cdap.api.data.schema.UnsupportedTypeException in project cdap by caskdata.

the class DefaultArtifactInspector method inspectApplications.

private ArtifactClasses.Builder inspectApplications(Id.Artifact artifactId, ArtifactClasses.Builder builder, Location artifactLocation, ClassLoader artifactClassLoader) throws IOException, InvalidArtifactException {
    // right now we force users to include the application main class as an attribute in their manifest,
    // which forces them to have a single application class.
    // in the future, we may want to let users do this or maybe specify a list of classes or
    // a package that will be searched for applications, to allow multiple applications in a single artifact.
    String mainClassName;
    try {
        Manifest manifest = BundleJarUtil.getManifest(artifactLocation);
        if (manifest == null) {
            return builder;
        }
        Attributes manifestAttributes = manifest.getMainAttributes();
        if (manifestAttributes == null) {
            return builder;
        }
        mainClassName = manifestAttributes.getValue(ManifestFields.MAIN_CLASS);
    } catch (ZipException e) {
        throw new InvalidArtifactException(String.format("Couldn't unzip artifact %s, please check it is a valid jar file.", artifactId), e);
    }
    if (mainClassName == null) {
        return builder;
    }
    try {
        Class<?> mainClass = artifactClassLoader.loadClass(mainClassName);
        if (!(Application.class.isAssignableFrom(mainClass))) {
            // possible for 3rd party plugin artifacts to have the main class set
            return builder;
        }
        Application app = (Application) mainClass.newInstance();
        java.lang.reflect.Type configType;
        // we can deserialize the config into that object. Otherwise it'll just be a Config
        try {
            configType = Artifacts.getConfigType(app.getClass());
        } catch (Exception e) {
            throw new InvalidArtifactException(String.format("Could not resolve config type for Application class %s in artifact %s. " + "The type must extend Config and cannot be parameterized.", mainClassName, artifactId));
        }
        Schema configSchema = configType == Config.class ? null : schemaGenerator.generate(configType);
        builder.addApp(new ApplicationClass(mainClassName, "", configSchema, getArtifactRequirements(app.getClass())));
    } catch (ClassNotFoundException e) {
        throw new InvalidArtifactException(String.format("Could not find Application main class %s in artifact %s.", mainClassName, artifactId));
    } catch (UnsupportedTypeException e) {
        throw new InvalidArtifactException(String.format("Config for Application %s in artifact %s has an unsupported schema. " + "The type must extend Config and cannot be parameterized.", mainClassName, artifactId));
    } catch (InstantiationException | IllegalAccessException e) {
        throw new InvalidArtifactException(String.format("Could not instantiate Application class %s in artifact %s.", mainClassName, artifactId), e);
    }
    return builder;
}
Also used : PluginConfig(io.cdap.cdap.api.plugin.PluginConfig) Config(io.cdap.cdap.api.Config) Schema(io.cdap.cdap.api.data.schema.Schema) Attributes(java.util.jar.Attributes) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ZipException(java.util.zip.ZipException) Manifest(java.util.jar.Manifest) InvalidMetadataException(io.cdap.cdap.common.InvalidMetadataException) ZipException(java.util.zip.ZipException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) EOFException(java.io.EOFException) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) IOException(java.io.IOException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) Application(io.cdap.cdap.api.app.Application) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException)

Example 9 with UnsupportedTypeException

use of io.cdap.cdap.api.data.schema.UnsupportedTypeException in project cdap by cdapio.

the class AvroRecordFormat method validateSchema.

@Override
protected void validateSchema(Schema desiredSchema) throws UnsupportedTypeException {
    try {
        // rather than check for all inconsistencies, just try to read the schema string as an Avro schema.
        avroFormatSchema = new org.apache.avro.Schema.Parser().parse(desiredSchema.toString());
        formatSchema = desiredSchema;
    } catch (SchemaParseException e) {
        throw new UnsupportedTypeException("Schema is not a valid avro schema.", e);
    } catch (Exception e) {
        throw new UnsupportedTypeException("Exception parsing schema as an avro schema.", e);
    }
}
Also used : SchemaParseException(org.apache.avro.SchemaParseException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) IOException(java.io.IOException) UnexpectedFormatException(io.cdap.cdap.api.data.format.UnexpectedFormatException) SchemaParseException(org.apache.avro.SchemaParseException)

Example 10 with UnsupportedTypeException

use of io.cdap.cdap.api.data.schema.UnsupportedTypeException in project cdap by cdapio.

the class DelimitedStringsRecordFormat method validateSchema.

@Override
protected void validateSchema(Schema desiredSchema) throws UnsupportedTypeException {
    // a valid schema is a record of simple types. In other words, no maps, arrays, records, unions, or enums allowed.
    // if mapping is null, the exception is the very last field, which is allowed to be an array of simple types.
    // These types may be nullable, which is a union of a null and non-null type.
    Iterator<Schema.Field> fields = desiredSchema.getFields().iterator();
    // check that each field is a simple field, except for the very last field, which can be an array of simple types.
    while (fields.hasNext()) {
        Schema.Field field = fields.next();
        Schema schema = field.getSchema();
        // if we're not on the very last field, the field must be a simple type or a nullable simple type.
        boolean isSimple = schema.getType().isSimpleType();
        boolean isNullableSimple = schema.isNullableSimple();
        if (!isSimple && !isNullableSimple) {
            // if this is the very last field and a string array, it is valid. otherwise it is not.
            if (fields.hasNext() || !isStringArray(schema)) {
                throw new UnsupportedTypeException("Field " + field.getName() + " is of invalid type.");
            }
        }
    }
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException)

Aggregations

UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)31 Schema (io.cdap.cdap.api.data.schema.Schema)18 IOException (java.io.IOException)12 SQLException (java.sql.SQLException)6 JsonObject (com.google.gson.JsonObject)4 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)4 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)4 InvalidArtifactException (io.cdap.cdap.common.InvalidArtifactException)4 ExploreException (io.cdap.cdap.explore.service.ExploreException)4 QueryHandle (io.cdap.cdap.proto.QueryHandle)4 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)4 Type (java.lang.reflect.Type)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 Config (io.cdap.cdap.api.Config)2 Plugin (io.cdap.cdap.api.annotation.Plugin)2 Application (io.cdap.cdap.api.app.Application)2 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)2 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)2 RecordScannable (io.cdap.cdap.api.data.batch.RecordScannable)2 RecordWritable (io.cdap.cdap.api.data.batch.RecordWritable)2