@Override public void init(Map stormConf, TopologyContext topologyContext, WriterConfiguration configuration) throws Exception { if(converter == null) { converter = new EnrichmentConverter(); } }
@Override protected HBaseExtractorState initialValue() { try { String cf = (String) config.get(LoadOptions.HBASE_CF).get(); HTableInterface table = provider.retrieve().getTable(hadoopConfig, (String) config.get(LoadOptions.HBASE_TABLE).get()); return new HBaseExtractorState(table, cf, handler.getExtractor(), new EnrichmentConverter(), hadoopConfig); } catch (IOException e1) { throw new IllegalStateException("Unable to get table: " + e1); } } };
public static List<LookupKV<EnrichmentKey, EnrichmentValue>> getValues() throws IOException { MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(TABLE_NAME); Assert.assertNotNull(table); List<LookupKV<EnrichmentKey, EnrichmentValue>> ret = new ArrayList<>(); EnrichmentConverter converter = new EnrichmentConverter(); for(Result r : table.getScanner(Bytes.toBytes(TABLE_CF))) { ret.add(converter.fromResult(r, TABLE_CF)); } return ret; } public static WriterConfiguration createConfig(final int batchSize, final Map<String, Object> sensorConfig)
@Override public void configure(String sensorName, WriterConfiguration configuration) { validateEnrichmentType(sensorName, configuration); validateKeyColumns(sensorName, configuration); String hbaseProviderImpl = Configurations.HBASE_PROVIDER.getAndConvert(configuration.getSensorConfig(sensorName),String.class); if(hbaseProviderImpl != null) { provider = ReflectionUtils.createInstance(hbaseProviderImpl); } if(converter == null) { converter = new EnrichmentConverter(); } LOG.debug("Sensor: '{}': {Provider: '{}', Converter: '{}'}", sensorName, getClassName(provider), getClassName(converter)); }
@Override public ReadinessState process(ComponentRunner runner) { MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(sensorType); if (table != null && table.size() == inputMessages.size()) { EnrichmentConverter converter = new EnrichmentConverter(); messages = new ArrayList<>(); try { for (Result r : table.getScanner(Bytes.toBytes("cf"))) { messages.add(converter.fromResult(r, "cf")); } } catch (IOException e) { } return ReadinessState.READY; } return ReadinessState.NOT_READY; }
@Test public void testValueConversion() throws IOException { EnrichmentConverter converter = new EnrichmentConverter(); EnrichmentKey k1 = new EnrichmentKey("type", "indicator"); EnrichmentValue v1 = new EnrichmentValue(new HashMap<String, Object>() {{ put("k1", "v1"); put("k2", "v2"); }}); Put serialized = converter.toPut("cf", k1, v1); LookupKV<EnrichmentKey, EnrichmentValue> kv = converter.fromPut(serialized,"cf"); Assert.assertEquals(k1, kv.getKey()); Assert.assertEquals(v1, kv.getValue()); } }