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);
}
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;
}
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));
}
Aggregations