public static void writeGlobalConfigToZookeeper(Map<String, Object> globalConfig, CuratorFramework client) throws Exception { writeGlobalConfigToZookeeper(JSONUtils.INSTANCE.toJSONPretty(globalConfig), client); }
public static void writeSensorParserConfigToZookeeper(String sensorType, SensorParserConfig sensorParserConfig, String zookeeperUrl) throws Exception { writeSensorParserConfigToZookeeper(sensorType, JSONUtils.INSTANCE.toJSONPretty(sensorParserConfig), zookeeperUrl); }
public static void writeSensorIndexingConfigToZookeeper(String sensorType, Map<String, Object> sensorIndexingConfig, String zookeeperUrl) throws Exception { writeSensorIndexingConfigToZookeeper(sensorType, JSONUtils.INSTANCE.toJSONPretty(sensorIndexingConfig), zookeeperUrl); }
public static void writeSensorEnrichmentConfigToZookeeper(String sensorType, SensorEnrichmentConfig sensorEnrichmentConfig, String zookeeperUrl) throws Exception { writeSensorEnrichmentConfigToZookeeper(sensorType, JSONUtils.INSTANCE.toJSONPretty(sensorEnrichmentConfig), zookeeperUrl); }
public byte[] toJSONPretty(String config) throws IOException { return toJSONPretty(readTree(config)); }
public static void writeConfigToZookeeper(String name, Map<String, Object> config, String zookeeperUrl) throws Exception { writeConfigToZookeeper(Constants.ZOOKEEPER_TOPOLOGY_ROOT + "/" + name, JSONUtils.INSTANCE.toJSONPretty(config), zookeeperUrl); }
public byte[] applyPatch(byte[] patch, byte[] source) throws IOException { JsonNode patchNode = readTree(patch); JsonNode sourceNode = readTree(source); return toJSONPretty(JsonPatch.apply(patchNode, sourceNode)); }
@Test public void modifiesSingleParserConfiguration() throws Exception { // write parser configuration ConfigurationType type = ConfigurationType.PARSER; String parserName = "a-happy-metron-parser"; byte[] config = JSONUtils.INSTANCE.toJSONPretty(someParserConfig); ConfigurationsUtils.writeConfigToZookeeper(type, Optional.of(parserName), config, zookeeperUrl); // validate the modified parser configuration byte[] actual = ConfigurationsUtils.readConfigBytesFromZookeeper(type, Optional.of(parserName), zookeeperUrl); assertThat(actual, equalTo(JSONUtils.INSTANCE.toJSONPretty(someParserConfig))); }
protected Put buildPut(Document update) throws IOException { Key k = new Key(update.getGuid(), update.getSensorType()); Put put = new Put(Key.toBytes(k)); long ts = update.getTimestamp() == null || update.getTimestamp() == 0 ? System.currentTimeMillis() : update.getTimestamp(); byte[] columnQualifier = Bytes.toBytes(ts); byte[] doc = JSONUtils.INSTANCE.toJSONPretty(update.getDocument()); put.addColumn(cf, columnQualifier, doc); return put; }
@Test public void patchesParserConfigurationViaPatchJSON() throws Exception { // setup zookeeper with a configuration final ConfigurationType type = ConfigurationType.PARSER; final String parserName = "patched-metron-parser"; byte[] config = JSONUtils.INSTANCE.toJSONPretty(someParserConfig); ConfigurationsUtils.writeConfigToZookeeper(type, Optional.of(parserName), config, zookeeperUrl); // patch the configuration byte[] patch = JSONUtils.INSTANCE.toJSONPretty(patchParserConfig); ConfigurationsUtils.applyConfigPatchToZookeeper(type, Optional.of(parserName), patch, zookeeperUrl); // validate the patched configuration byte[] actual = ConfigurationsUtils.readConfigBytesFromZookeeper(type, Optional.of(parserName), zookeeperUrl); byte[] expected = JSONUtils.INSTANCE.toJSONPretty(modifiedParserConfig); assertThat(actual, equalTo(expected)); }
@Test public void modifiedGlobalConfiguration() throws Exception { // write global configuration ConfigurationType type = ConfigurationType.GLOBAL; ConfigurationsUtils.writeConfigToZookeeper(type, JSONUtils.INSTANCE.toJSONPretty(someParserConfig), zookeeperUrl); // validate the modified global configuration byte[] actual = ConfigurationsUtils.readConfigBytesFromZookeeper(type, zookeeperUrl); assertThat(actual, equalTo(JSONUtils.INSTANCE.toJSONPretty(someParserConfig))); }
private static List<byte[]> getInputMessages(String path){ try{ List<byte[]> ret = TestUtils.readSampleData(path); { //we want one of the fields without a destination IP to ensure that enrichments can function Map<String, Object> sansDestinationIp = JSONUtils.INSTANCE.load(new String(ret.get(ret.size() -1)) , JSONUtils.MAP_SUPPLIER); sansDestinationIp.remove(Constants.Fields.DST_ADDR.getName()); ret.add(JSONUtils.INSTANCE.toJSONPretty(sansDestinationIp)); } return ret; }catch(IOException ioe){ return null; } }
@Test public void testPatchParserFromKeyValue() throws Exception { // push the parser config File configFile = new File(parsersDir, "myparser.json"); TestUtils.write(configFile, squidParserConfig); pushConfigs(PARSER, configDir, Optional.of("myparser")); // patch the parser configuration patchConfigs(PARSER, Optional.empty(), Optional.of("myparser"), Optional.of(ADD), Optional.of("/parserConfig/timestampField"), Optional.of("\"\"heyjoe\"\"")); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedPatchedParser); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PARSER, Optional.of("myparser")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPatchGlobalFromComplexKeyValue() throws Exception { // write a global configuration File configFile = new File(configDir, "global.json"); TestUtils.write(configFile, globalConfig); pushConfigs(GLOBAL, configDir, Optional.of("global")); // patch the global configuration patchConfigs(GLOBAL, Optional.empty(), Optional.of("global"), Optional.of(ADD), Optional.of("/foo"), Optional.of("{ \"bar\" : { \"baz\" : [ \"bazval1\", \"bazval2\" ] } }")); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedComplexConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(GLOBAL, Optional.of("global")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushIndexing() throws Exception { // write the indexing config File configFile = new File(indexingDir, "myindex.json"); TestUtils.write(configFile, someIndexingConfig); // push the index config pushConfigs(INDEXING, configDir, Optional.of("myindex")); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(someIndexingConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(INDEXING, Optional.of("myindex")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushParser() throws Exception { // create a parser config File configFile = new File(parsersDir, "myparser.json"); TestUtils.write(configFile, squidParserConfig); // push the parser config pushConfigs(PARSER, configDir, Optional.of("myparser")); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(squidParserConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PARSER, Optional.of("myparser")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushEnrichment() throws Exception { // create enrichment config File configFile = new File(enrichmentsDir, "myenrichment.json"); TestUtils.write(configFile, someEnrichmentConfig); // push enrichment config pushConfigs(ENRICHMENT, configDir, Optional.of("myenrichment")); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(someEnrichmentConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(ENRICHMENT, Optional.of("myenrichment")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPatchGlobalFromFile() throws Exception { // create a patch file File patchFile = new File(tmpDir, "global-config-patch.json"); TestUtils.write(patchFile, somePatchConfig); // create the global config File configFile = new File(configDir, "global.json"); TestUtils.write(configFile, globalConfig); pushConfigs(GLOBAL, configDir, Optional.of("global")); // patch the global config patchConfigs(GLOBAL, Optional.of(patchFile), Optional.of("global"), Optional.empty(), Optional.empty(), Optional.empty()); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedSomeConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(GLOBAL, Optional.of("global")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushGlobal() throws Exception { // create the config File configFile = new File(configDir, "global.json"); TestUtils.write(configFile, globalConfig); // push the global config pushConfigs(GLOBAL, configDir); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(globalConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(GLOBAL), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushProfiler() throws Exception { // create the profiler config File configFile = new File(configDir, "profiler.json"); TestUtils.write(configFile, someProfilerConfig); // push the profiler config Optional<String> configName = Optional.empty(); pushConfigs(PROFILER, configDir, configName); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(someProfilerConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PROFILER, configName), 1)); Assert.assertThat(actual, equalTo(expected)); }