@Override public void init(Map stormConf, TopologyContext topologyContext, WriterConfiguration configuration) throws Exception { if(converter == null) { converter = new EnrichmentConverter(); } }
@Override public LookupKV<EnrichmentKey, EnrichmentValue> fromResult(Result result, String columnFamily) throws IOException { return fromResult(result, columnFamily, new EnrichmentKey(), new EnrichmentValue()); } }
@Override public LookupKV<EnrichmentKey, EnrichmentValue> fromPut(Put put, String columnFamily) throws IOException { return fromPut(put, columnFamily, new EnrichmentKey(), new EnrichmentValue()); }
@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()); } }
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)
public void load(HTableInterface table, String cf, Iterable<LookupKV<EnrichmentKey, EnrichmentValue>> results) throws IOException { for(LookupKV<EnrichmentKey, EnrichmentValue> result : results) { Put put = converter.toPut(cf, result.getKey(), result.getValue()); table.put(put); } } }
@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; }
kv.getValue().getMetadata().put("taxii_url", endpoint.toString()); kv.getValue().getMetadata().put("taxii_collection", collection); Put p = converter.toPut(columnFamily, kv.getKey(), kv.getValue()); HTableInterface table = getTable(hbaseTable); table.put(p);
@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); } } };
continue; Put put = converter.toPut(this.cf, key, value); if(put != null) { LOG.debug("Put: {Column Family: '{}', Key: '{}', Value: '{}'}", this.cf, key, value);
@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)); }