Search in sources :

Example 1 with KafkaConnectSchemaType

use of io.atlasmap.kafkaconnect.v2.KafkaConnectSchemaType in project atlasmap by atlasmap.

the class KafkaConnectModule method extractSchema.

private org.apache.kafka.connect.data.Schema extractSchema(DataSourceMetadata meta) throws AtlasException {
    if (meta == null || meta.getSpecification() == null) {
        return null;
    }
    byte[] bytes = meta.getSpecification();
    String schema = new String(bytes);
    String typeStr = meta.getInspectionParameters().get(KafkaConnectConstants.OPTIONS_SCHEMA_TYPE);
    KafkaConnectSchemaType type = KafkaConnectSchemaType.valueOf(typeStr);
    HashMap<String, Object> options = KafkaConnectUtil.repackParserOptions(meta.getInspectionParameters());
    try {
        switch(type) {
            case JSON:
                return KafkaConnectUtil.parseJson(schema, options);
            case AVRO:
                return KafkaConnectUtil.parseAvro(schema, options);
            default:
                LOG.warn("Ignoring unsupported KafkaConnect schema type '{}'", type);
                return null;
        }
    } catch (Exception e) {
        throw new AtlasException(e);
    }
}
Also used : KafkaConnectSchemaType(io.atlasmap.kafkaconnect.v2.KafkaConnectSchemaType) AtlasException(io.atlasmap.api.AtlasException) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException)

Example 2 with KafkaConnectSchemaType

use of io.atlasmap.kafkaconnect.v2.KafkaConnectSchemaType in project atlasmap by atlasmap.

the class KafkaConnectService method inspect.

/**
 * Inspects a Kafka Connect schema and return a Document object.
 * @param request request
 * @return {@link KafkaConnectInspectionResponse}
 */
public Response inspect(KafkaConnectInspectionRequest request) {
    long startTime = System.currentTimeMillis();
    KafkaConnectInspectionResponse response = new KafkaConnectInspectionResponse();
    KafkaConnectDocument d = null;
    try {
        ClassLoader loader = resourceContext != null ? resourceContext.getResource(AtlasService.class).getLibraryLoader() : KafkaConnectService.class.getClassLoader();
        KafkaConnectInspectionService s = new KafkaConnectInspectionService(loader);
        String schemaTypeStr = request.getOptions().get(KafkaConnectConstants.OPTIONS_SCHEMA_TYPE);
        KafkaConnectSchemaType schemaType = KafkaConnectSchemaType.valueOf(schemaTypeStr);
        HashMap<String, Object> options = KafkaConnectUtil.repackParserOptions(request.getOptions());
        switch(schemaType) {
            case JSON:
                d = s.inspectJson(request.getSchemaData(), options);
                break;
            case AVRO:
                d = s.inspectAvro(request.getSchemaData(), options);
                break;
            default:
                response.setErrorMessage("Unsupported inspection type: " + schemaType);
                break;
        }
    } catch (Exception e) {
        LOG.error("Error inspecting Kafka Connect schema: " + e.getMessage(), e);
        response.setErrorMessage(e.getMessage());
    } finally {
        response.setExecutionTime(System.currentTimeMillis() - startTime);
    }
    response.setKafkaConnectDocument(d);
    return Response.ok().entity(toJson(response)).build();
}
Also used : KafkaConnectSchemaType(io.atlasmap.kafkaconnect.v2.KafkaConnectSchemaType) KafkaConnectInspectionResponse(io.atlasmap.kafkaconnect.v2.KafkaConnectInspectionResponse) KafkaConnectInspectionService(io.atlasmap.kafkaconnect.inspect.KafkaConnectInspectionService) KafkaConnectDocument(io.atlasmap.kafkaconnect.v2.KafkaConnectDocument) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

KafkaConnectSchemaType (io.atlasmap.kafkaconnect.v2.KafkaConnectSchemaType)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AtlasException (io.atlasmap.api.AtlasException)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 KafkaConnectInspectionService (io.atlasmap.kafkaconnect.inspect.KafkaConnectInspectionService)1 KafkaConnectDocument (io.atlasmap.kafkaconnect.v2.KafkaConnectDocument)1 KafkaConnectInspectionResponse (io.atlasmap.kafkaconnect.v2.KafkaConnectInspectionResponse)1 IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1