/** * Reads the Enrichment configuration from Zookeeper. * * @param sensorType The type of sensor. * @param client The Zookeeper client. * @return The Enrichment configuration for the given sensor type, if one exists. Otherwise, null. * @throws Exception */ public static SensorEnrichmentConfig readSensorEnrichmentConfigFromZookeeper(String sensorType, CuratorFramework client) throws Exception { SensorEnrichmentConfig config = null; Optional<byte[]> bytes = readFromZookeeperSafely(ENRICHMENT.getZookeeperRoot() + "/" + sensorType, client); if (bytes.isPresent()) { config = SensorEnrichmentConfig.fromBytes(bytes.get()); } return config; }
@Override public SensorEnrichmentConfig readConfig(String sensor) throws Exception { SensorEnrichmentConfig sensorEnrichmentConfig = new SensorEnrichmentConfig(); try { sensorEnrichmentConfig = SensorEnrichmentConfig.fromBytes(ConfigurationsUtils.readSensorEnrichmentConfigBytesFromZookeeper(sensor, client)); }catch (KeeperException.NoNodeException e) { } return sensorEnrichmentConfig; }
@Test public void testSerDe() throws IOException { for(File enrichmentConfig : new File(new File(TestConstants.ENRICHMENTS_CONFIGS_PATH), "enrichments").listFiles()) { SensorEnrichmentConfig config = null; try (BufferedReader br = new BufferedReader(new FileReader(enrichmentConfig))) { String parserStr = IOUtils.toString(br); config = SensorEnrichmentConfig.fromBytes(parserStr.getBytes()); } SensorEnrichmentConfig config2 = SensorEnrichmentConfig.fromBytes(config.toJSON().getBytes()); Assert.assertEquals(config2, config); } } }
@Test public void test() throws IOException { EqualsVerifier.forClass(SensorEnrichmentConfig.class).suppress(Warning.NONFINAL_FIELDS).usingGetClass().verify(); Map<String, byte[]> testSensorConfigMap = ConfigurationsUtils.readSensorEnrichmentConfigsFromFile(TestConstants.ENRICHMENTS_CONFIGS_PATH); byte[] sensorConfigBytes = testSensorConfigMap.get("yaf"); SensorEnrichmentConfig sensorEnrichmentConfig = SensorEnrichmentConfig.fromBytes(sensorConfigBytes); Assert.assertNotNull(sensorEnrichmentConfig); Assert.assertTrue(sensorEnrichmentConfig.toString() != null && sensorEnrichmentConfig.toString().length() > 0); }
fromBytes(ConfigurationsUtils.readSensorEnrichmentConfigsFromFile(TestConstants.SAMPLE_CONFIG_PATH).get(sensorType)); sensorEnrichmentConfig.getConfiguration().put(GenericEnrichmentBolt.STELLAR_CONTEXT_CONF, genericEnrichmentBolt.getStellarContext()); CacheKey cacheKey1 = new CacheKey("field1", "value1", sensorEnrichmentConfig);