Search in sources :

Example 1 with SerDesPair

use of com.hortonworks.registries.schemaregistry.SerDesPair in project registry by hortonworks.

the class SampleSchemaRegistryClientApp method registerSimpleSerDes.

private Long registerSimpleSerDes(String fileId) {
    String simpleSerializerClassName = "org.apache.schemaregistry.samples.serdes.SimpleSerializer";
    String simpleDeserializerClassName = "org.apache.schemaregistry.samples.serdes.SimpleDeserializer";
    SerDesPair serializerInfo = new SerDesPair("simple-serializer", "simple serializer", fileId, simpleSerializerClassName, simpleDeserializerClassName);
    return schemaRegistryClient.addSerDes(serializerInfo);
}
Also used : SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair)

Example 2 with SerDesPair

use of com.hortonworks.registries.schemaregistry.SerDesPair in project registry by hortonworks.

the class SchemaRegistryClient method createInstance.

private <T> T createInstance(SerDesInfo serDesInfo, boolean isSerializer) {
    Set<Class<?>> interfaceClasses = isSerializer ? SERIALIZER_INTERFACE_CLASSES : DESERIALIZER_INTERFACE_CLASSES;
    if (interfaceClasses == null || interfaceClasses.isEmpty()) {
        throw new IllegalArgumentException("interfaceClasses array must be neither null nor empty.");
    }
    // loading serializer, create a class loader and and keep them in cache.
    final SerDesPair serDesPair = serDesInfo.getSerDesPair();
    String fileId = serDesPair.getFileId();
    // get class loader for this file ID
    ClassLoader classLoader = classLoaderCache.getClassLoader(fileId);
    T t;
    try {
        String className = isSerializer ? serDesPair.getSerializerClassName() : serDesPair.getDeserializerClassName();
        Class<T> clazz = (Class<T>) Class.forName(className, true, classLoader);
        t = clazz.newInstance();
        List<Class<?>> classes = new ArrayList<>();
        for (Class<?> interfaceClass : interfaceClasses) {
            if (interfaceClass.isAssignableFrom(clazz)) {
                classes.add(interfaceClass);
            }
        }
        if (classes.isEmpty()) {
            throw new RuntimeException("Given Serialize/Deserializer " + className + " class does not implement any " + "one of the registered interfaces: " + interfaceClasses);
        }
        Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), classes.toArray(new Class[classes.size()]), new ClassLoaderAwareInvocationHandler(classLoader, t));
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new SerDesException(e);
    }
    return t;
}
Also used : ArrayList(java.util.ArrayList) DEFAULT_CONNECTION_TIMEOUT(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.Configuration.DEFAULT_CONNECTION_TIMEOUT) DEFAULT_READ_TIMEOUT(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.Configuration.DEFAULT_READ_TIMEOUT) ClassLoaderAwareInvocationHandler(com.hortonworks.registries.common.util.ClassLoaderAwareInvocationHandler) SerDesException(com.hortonworks.registries.schemaregistry.serde.SerDesException) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair)

Example 3 with SerDesPair

use of com.hortonworks.registries.schemaregistry.SerDesPair in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testSerializerOps.

@Test
public void testSerializerOps() throws Exception {
    String fileId = uploadFile();
    SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BOTH);
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/device.avsc"), "Initial version of the schema"));
    SerDesPair serDesPair = createSerDesInfo(fileId);
    Long serDesId = SCHEMA_REGISTRY_CLIENT.addSerDes(serDesPair);
    Assert.assertNotNull("Returned serDesId can not be null", serDesId);
    String schemaName = schemaMetadata.getName();
    SCHEMA_REGISTRY_CLIENT.mapSchemaWithSerDes(schemaName, serDesId);
    Collection<SerDesInfo> serializers = SCHEMA_REGISTRY_CLIENT.getSerDes(schemaName);
    Assert.assertTrue(serializers.stream().map(x -> x.getSerDesPair()).collect(Collectors.toList()).contains(serDesPair));
}
Also used : Arrays(java.util.Arrays) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) SchemaRegistryTestProfileType(com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType) SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) SERDES_PROTOCOL_VERSION(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer.SERDES_PROTOCOL_VERSION) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) AvroSnapshotSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) Utf8(org.apache.avro.util.Utf8) SerDesProtocolHandlerRegistry(com.hortonworks.registries.schemaregistry.serdes.avro.SerDesProtocolHandlerRegistry) AvroSnapshotDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer) SchemaRegistryTestName(com.hortonworks.registries.schemaregistry.avro.util.SchemaRegistryTestName) Collection(java.util.Collection) BAD_REQUEST_PARAM_MISSING(com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.BAD_REQUEST_PARAM_MISSING) Set(java.util.Set) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) Response(javax.ws.rs.core.Response) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) CustomParameterizedRunner(com.hortonworks.registries.schemaregistry.avro.util.CustomParameterizedRunner) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) UNSUPPORTED_SCHEMA_TYPE(com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE) IntStream(java.util.stream.IntStream) SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) AvroSchemaRegistryClientUtil(com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SchemaValidationLevel(com.hortonworks.registries.schemaregistry.SchemaValidationLevel) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) Files(java.nio.file.Files) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) FileOutputStream(java.io.FileOutputStream) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) Test(org.junit.Test) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Maps(com.google.common.collect.Maps) File(java.io.File) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Rule(org.junit.Rule) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) Assert(org.junit.Assert) Collections(java.util.Collections) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) InputStream(java.io.InputStream) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Aggregations

SerDesPair (com.hortonworks.registries.schemaregistry.SerDesPair)3 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Maps (com.google.common.collect.Maps)1 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)1 BAD_REQUEST_PARAM_MISSING (com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.BAD_REQUEST_PARAM_MISSING)1 UNSUPPORTED_SCHEMA_TYPE (com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE)1 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)1 ClassLoaderAwareInvocationHandler (com.hortonworks.registries.common.util.ClassLoaderAwareInvocationHandler)1 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)1 SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)1 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)1 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)1 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)1 SchemaValidationLevel (com.hortonworks.registries.schemaregistry.SchemaValidationLevel)1 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)1 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)1 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)1 SerDesInfo (com.hortonworks.registries.schemaregistry.SerDesInfo)1 SchemaRegistryTestProfileType (com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType)1