use of org.apache.samza.serializers.SerializableSerde in project samza by apache.
the class TestJobNodeConfigurationGenerator method validateAndGetDeserializedSerdes.
private Map<String, Serde> validateAndGetDeserializedSerdes(Config jobConfig, int numSerdes) {
Config serializers = jobConfig.subset("serializers.registry.", true);
// make sure that the serializers deserialize correctly
SerializableSerde<Serde> serializableSerde = new SerializableSerde<>();
assertEquals(numSerdes, serializers.size());
return serializers.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().replace(SerializerConfig.SERIALIZED_INSTANCE_SUFFIX, ""), e -> serializableSerde.fromBytes(Base64.getDecoder().decode(e.getValue().getBytes()))));
}
use of org.apache.samza.serializers.SerializableSerde in project samza by apache.
the class TableConfigGenerator method generateSerdeConfig.
/**
* Generate serde configuration for provided tables
*
* @param tableDescriptors table descriptors, for which serde configuration to be generated
* @return serde configuration for tables
*/
public static Map<String, String> generateSerdeConfig(List<TableDescriptor> tableDescriptors) {
Map<String, String> serdeConfigs = new HashMap<>();
// Collect key and msg serde instances for all the tables
Map<String, Serde> tableKeySerdes = new HashMap<>();
Map<String, Serde> tableValueSerdes = new HashMap<>();
HashSet<Serde> serdes = new HashSet<>();
tableDescriptors.stream().filter(d -> d instanceof LocalTableDescriptor).forEach(d -> {
LocalTableDescriptor ld = (LocalTableDescriptor) d;
tableKeySerdes.put(ld.getTableId(), ld.getSerde().getKeySerde());
tableValueSerdes.put(ld.getTableId(), ld.getSerde().getValueSerde());
});
serdes.addAll(tableKeySerdes.values());
serdes.addAll(tableValueSerdes.values());
// Generate serde names
SerializableSerde<Serde> serializableSerde = new SerializableSerde<>();
Base64.Encoder base64Encoder = Base64.getEncoder();
Map<Serde, String> serdeUUIDs = new HashMap<>();
serdes.forEach(serde -> {
String serdeName = serdeUUIDs.computeIfAbsent(serde, s -> serde.getClass().getSimpleName() + "-" + UUID.randomUUID().toString());
serdeConfigs.putIfAbsent(String.format(SerializerConfig.SERDE_SERIALIZED_INSTANCE, serdeName), base64Encoder.encodeToString(serializableSerde.toBytes(serde)));
});
// Set key and msg serdes for tables to the serde names generated above
tableKeySerdes.forEach((tableId, serde) -> {
String keySerdeConfigKey = String.format(JavaTableConfig.STORE_KEY_SERDE, tableId);
serdeConfigs.put(keySerdeConfigKey, serdeUUIDs.get(serde));
});
tableValueSerdes.forEach((tableId, serde) -> {
String valueSerdeConfigKey = String.format(JavaTableConfig.STORE_MSG_SERDE, tableId);
serdeConfigs.put(valueSerdeConfigKey, serdeUUIDs.get(serde));
});
return serdeConfigs;
}
Aggregations