private Map<String, Object> getGlobalConfig(Optional<CuratorFramework> zkClient) { if (zkClient.isPresent()) { try { return JSONUtils.INSTANCE.load( new ByteArrayInputStream(ConfigurationsUtils.readGlobalConfigBytesFromZookeeper(zkClient.get())), JSONUtils.MAP_SUPPLIER); } catch (Exception e) { LOG.warn("Exception thrown while attempting to get global config from Zookeeper.", e); } } return new LinkedHashMap<>(); }
public static void updateConfigsFromZookeeper(Configurations configurations, CuratorFramework client) throws Exception { configurations.updateGlobalConfig(readGlobalConfigBytesFromZookeeper(client)); }
public static void setupStellarStatically(CuratorFramework client) throws Exception { byte[] ret = null; try { ret = readGlobalConfigBytesFromZookeeper(client); } catch(KeeperException.NoNodeException nne) { //can't find the node } if(ret == null || ret.length == 0) { setupStellarStatically(client, Optional.empty()); } else { setupStellarStatically(client, Optional.of(new String(ret))); } }
protected void pushConfig(Path srcPath, Path dstPath, String configName, String zookeeper) { System.out.println("Beginning update of global configs"); try (CuratorFramework client = ConfigurationsUtils.getClient(zookeeper)) { client.start(); // Use the parent and place a new file. Has to be a new file so we can update the configs and trigger updates. // Fetch the global configuration Map<String, Object> global = JSONUtils.INSTANCE.load( new ByteArrayInputStream(ConfigurationsUtils.readGlobalConfigBytesFromZookeeper(client)), JSONUtils.MAP_SUPPLIER); // Update the global config and push it back global.put(configName, dstPath.toString() + "/" + srcPath.getName()); ConfigurationsUtils.writeGlobalConfigToZookeeper(global, client); } catch (Exception e) { System.err.println("Unable to load new GeoLite2 config for " + configName + " into HDFS: " + e); e.printStackTrace(); System.exit(2); } System.out.println("Finished update of global configs"); }
@Test public void test() throws Exception { Assert.assertTrue(expectedGlobalConfig.length > 0); ConfigurationsUtils.writeGlobalConfigToZookeeper(expectedGlobalConfig, zookeeperUrl); byte[] actualGlobalConfigBytes = ConfigurationsUtils.readGlobalConfigBytesFromZookeeper(client); Assert.assertTrue(Arrays.equals(expectedGlobalConfig, actualGlobalConfigBytes)); Assert.assertTrue(expectedSensorParserConfigMap.size() > 0); String testSensorType = "yaf"; byte[] expectedSensorParserConfigBytes = expectedSensorParserConfigMap.get(testSensorType); ConfigurationsUtils.writeSensorParserConfigToZookeeper(testSensorType, expectedSensorParserConfigBytes, zookeeperUrl); byte[] actualSensorParserConfigBytes = ConfigurationsUtils.readSensorParserConfigBytesFromZookeeper(testSensorType, client); Assert.assertTrue(Arrays.equals(expectedSensorParserConfigBytes, actualSensorParserConfigBytes)); Assert.assertTrue(expectedSensorEnrichmentConfigMap.size() > 0); byte[] expectedSensorEnrichmentConfigBytes = expectedSensorEnrichmentConfigMap.get(testSensorType); ConfigurationsUtils.writeSensorEnrichmentConfigToZookeeper(testSensorType, expectedSensorEnrichmentConfigBytes, zookeeperUrl); byte[] actualSensorEnrichmentConfigBytes = ConfigurationsUtils.readSensorEnrichmentConfigBytesFromZookeeper(testSensorType, client); Assert.assertTrue(Arrays.equals(expectedSensorEnrichmentConfigBytes, actualSensorEnrichmentConfigBytes)); String name = "testConfig"; Map<String, Object> testConfig = new HashMap<>(); testConfig.put("stringField", "value"); testConfig.put("intField", 1); testConfig.put("doubleField", 1.1); ConfigurationsUtils.writeConfigToZookeeper(name, testConfig, zookeeperUrl); byte[] readConfigBytes = ConfigurationsUtils.readConfigBytesFromZookeeper(name, client); Assert.assertTrue(Arrays.equals(JSONUtils.INSTANCE.toJSONPretty(testConfig), readConfigBytes)); }