@Override public Object apply(String s) { return deserialize(s); }
public static void writeGlobalConfigToZookeeper(byte[] globalConfig, CuratorFramework client) throws Exception { GLOBAL.deserialize(new String(globalConfig)); writeToZookeeper(GLOBAL.getZookeeperRoot(), globalConfig, client); }
private static File getFile(File baseDir, ConfigurationType configurationType, String name) { return new File(new File(baseDir, configurationType.getDirectory()), name + ".json"); }
public static void visitConfigs(CuratorFramework client, ConfigurationVisitor callback, ConfigurationType configType, Optional<String> configName) throws Exception { if (client.checkExists().forPath(configType.getZookeeperRoot()) != null) { if (configType.equals(GLOBAL)) { byte[] globalConfigData = client.getData().forPath(configType.getZookeeperRoot()); callback.visit(configType, "global", new String(globalConfigData)); } else if(configType.equals(PROFILER)) { byte[] profilerConfigData = client.getData().forPath(configType.getZookeeperRoot()); callback.visit(configType, "profiler", new String(profilerConfigData)); } else if (configType.equals(PARSER) || configType.equals(ENRICHMENT) || configType.equals(INDEXING)) { if (configName.isPresent()) { byte[] data = readConfigBytesFromZookeeper(configType, configName, client); callback.visit(configType, configName.get(), new String(data)); } else { List<String> children = client.getChildren().forPath(configType.getZookeeperRoot()); for (String child : children) { byte[] data = client.getData().forPath(configType.getZookeeperRoot() + "/" + child); callback.visit(configType, child, new String(data)); } } } } }
private static String getConfigZKPath(ConfigurationType configType, Optional<String> configName) { String pathSuffix = configName.isPresent() && configType != GLOBAL ? "/" + configName.get() : ""; return configType.getZookeeperRoot() + pathSuffix; }
public static String getKey(String sensorType) { return ConfigurationType.PARSER.getTypeName() + "." + sensorType; } }
/** * 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); } } }
push(inputDirStr, client, ConfigurationType.valueOf(configType.get()), configName); } else { push(inputDirStr, client); dump(client, ConfigurationType.valueOf(configType.get()), configName); } else { dump(client); Optional<String> patchKey = Optional.ofNullable(ConfigurationOptions.PATCH_KEY.get(cli)); Optional<String> patchValue = Optional.ofNullable(ConfigurationOptions.PATCH_VALUE.get(cli)); patch(client, ConfigurationType.valueOf(configType.get()), configName, patchMode, patchPath, patchKey, patchValue); } else { throw new IllegalArgumentException("Patch requires config type");
private void pushConfigs(ConfigurationType type, File configPath, Optional<String> configName) throws Exception { String[] args = new String[]{ "-z", zookeeperUrl, "--mode", "PUSH", "--config_type", type.toString(), "--input_dir", configPath.getAbsolutePath() }; if (configName.isPresent()) { args = ArrayUtils.addAll(args, "--config_name", configName.get()); } ConfigurationManager manager = new ConfigurationManager(); manager.run(ConfigurationManager.ConfigurationOptions.parse(new PosixParser(), args)); }
for (String sensorType : configs.keySet()) { byte[] configData = configs.get(sensorType); type.writeSensorConfigToZookeeper(sensorType, configData, client);
private ProfilerConfig readFromZookeeper(CuratorFramework client) throws Exception { byte[] raw = client.getData().forPath(PROFILER.getZookeeperRoot()); return JSONUtils.INSTANCE.load(new ByteArrayInputStream(raw), ProfilerConfig.class); }
public static String getKey(String sensorType) { return ConfigurationType.ENRICHMENT.getTypeName() + "." + sensorType; }
/** * Delete callback, this is called whenever a path is deleted 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 delete(CuratorFramework client, String path, byte[] data) throws IOException { String name = path.substring(path.lastIndexOf("/") + 1); if (path.startsWith(getType().getZookeeperRoot())) { LOG.debug("Deleting {} {} config from internal cache", getType().name(), name); delete(name); reloadCallback(name, getType()); } else if (ConfigurationType.GLOBAL.getZookeeperRoot().equals(path)) { LOG.debug("Deleting global config from internal cache"); getConfigurations().deleteGlobalConfig(); reloadCallback(name, ConfigurationType.GLOBAL); } }
ConfigurationType type = ConfigurationType.valueOf(arg0);
private void patchConfigs(ConfigurationType type, Optional<File> patchPath, Optional<String> configName, Optional<PatchMode> patchMode, Optional<String> key, Optional<String> value) throws Exception { String[] args = new String[]{ "-z", zookeeperUrl, "--mode", "PATCH", "--config_type", type.toString() }; if (configName.isPresent()) { args = ArrayUtils.addAll(args, "--config_name", configName.get()); } if (patchPath.isPresent()) { args = ArrayUtils.addAll(args, "--patch_file", patchPath.get().getAbsolutePath()); } else if (patchMode.isPresent()) { args = ArrayUtils.addAll(args, "--patch_mode", patchMode.get().toString(), "--patch_key", key.get(), "--patch_value", value.get()); } ConfigurationManager manager = new ConfigurationManager(); manager.run(ConfigurationManager.ConfigurationOptions.parse(new PosixParser(), args)); }
/** * Writes all config content to the provided print stream. * * @param out stream to use as output * @param client zk client * @throws Exception */ public static void dumpConfigs(PrintStream out, CuratorFramework client) throws Exception { ConfigurationsUtils.visitConfigs(client, (type, name, data) -> { type.deserialize(data); out.println(type + " Config: " + name + System.lineSeparator() + data); }); }
public static void writeProfilerConfigToZookeeper(byte[] config, CuratorFramework client) throws Exception { PROFILER.deserialize(new String(config)); writeToZookeeper(PROFILER.getZookeeperRoot(), config, client); }
public static byte[] readGlobalConfigBytesFromZookeeper(CuratorFramework client) throws Exception { return readFromZookeeper(GLOBAL.getZookeeperRoot(), client); }
public static String getKey() { return ConfigurationType.PROFILER.getTypeName(); }
ConfigurationType configType, Optional<String> configName) throws IOException { Map<String, byte[]> sensorConfigs = new HashMap<>(); File configPath = new File(rootPath, configType.getDirectory()); if (configPath.exists() && configPath.isDirectory()) { File[] children = configPath.listFiles();