public void updateGlobalConfig(byte[] data) throws IOException { if (data == null) throw new IllegalStateException("global config data cannot be null"); updateGlobalConfig(new ByteArrayInputStream(data)); }
public void updateGlobalConfig(InputStream io) throws IOException { Map<String, Object> globalConfig = JSONUtils.INSTANCE.load(io, JSONUtils.MAP_SUPPLIER); updateGlobalConfig(globalConfig); }
public static void updateConfigsFromZookeeper(Configurations configurations, CuratorFramework client) throws Exception { configurations.updateGlobalConfig(readGlobalConfigBytesFromZookeeper(client)); }
public Configurations getConfiguration(String config) throws IOException { Configurations configurations = new Configurations(); configurations.updateGlobalConfig(Bytes.toBytes(config)); return configurations; }
/** * Update callback, this is called whenever a path is updated in zookeeper which we are monitoring. * * @param client The CuratorFramework * @param path The zookeeper path * @param data The change. * @throws IOException When update is impossible. */ public void update(CuratorFramework client, String path, byte[] data) throws IOException { if (data.length != 0) { String name = path.substring(path.lastIndexOf("/") + 1); if (path.startsWith(getType().getZookeeperRoot())) { LOG.debug("Updating the {} config: {} -> {}", getType().name(), name, new String(data == null?"".getBytes():data)); update(name, data); reloadCallback(name, getType()); } else if (ConfigurationType.GLOBAL.getZookeeperRoot().equals(path)) { LOG.debug("Updating the global config: {}", new String(data == null?"".getBytes():data)); getConfigurations().updateGlobalConfig(data); reloadCallback(name, ConfigurationType.GLOBAL); } } }
public static Configurations getSampleConfigs() throws IOException { Configurations configurations = new Configurations(); configurations.updateGlobalConfig(ConfigurationsUtils.readGlobalConfigFromFile(TestConstants.SAMPLE_CONFIG_PATH)); return configurations; }
@Test public void test() throws IOException { EqualsVerifier.forClass(Configurations.class).suppress(Warning.NONFINAL_FIELDS, Warning.NULL_FIELDS).usingGetClass().verify(); Configurations configurations = new Configurations(); try { configurations.updateGlobalConfig((byte[]) null); Assert.fail("Updating a config with null should throw an IllegalStateException"); } catch(IllegalStateException e) {} Assert.assertTrue(configurations.toString() != null && configurations.toString().length() > 0); } }