Github user cestella commented on a diff in the pull request: https://github.com/apache/metron/pull/851#discussion_r154202685 --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/ConfigurationsUtils.java --- @@ -343,25 +343,57 @@ public static void uploadConfigsToZookeeper(String rootFilePath, CuratorFramewor * @param type config type to upload configs for * @param configName specific config under the specified config type */ - public static void uploadConfigsToZookeeper(String rootFilePath, CuratorFramework client, - ConfigurationType type, Optional<String> configName) throws Exception { + public static void uploadConfigsToZookeeper( + String rootFilePath, + CuratorFramework client, + ConfigurationType type, + Optional<String> configName) throws Exception { + switch (type) { + case GLOBAL: final byte[] globalConfig = readGlobalConfigFromFile(rootFilePath); if (globalConfig.length > 0) { setupStellarStatically(client, Optional.of(new String(globalConfig))); writeGlobalConfigToZookeeper(globalConfig, client); } break; - case PARSER: // intentional pass-through - case ENRICHMENT: // intentional pass-through - case INDEXING: - Map<String, byte[]> sensorIndexingConfigs = readSensorConfigsFromFile(rootFilePath, type, - configName); - for (String sensorType : sensorIndexingConfigs.keySet()) { - writeConfigToZookeeper(type, configName, sensorIndexingConfigs.get(sensorType), client); + + case PARSER: { + Map<String, byte[]> configs = readSensorConfigsFromFile(rootFilePath, PARSER, configName); --- End diff -- These cases look like they are cut and pasted which seems like code smell to me and might be a maintenance issue. Can we extract the common code for Parser, Enrichment, and Indexing into a separate function that is called here? Perhaps something like: ``` void writeSensorConfigs(ConfigurationType type, Optional<String> configName, BiFunction<String, byte[], Void> callback) { Map<String, byte[]> configs = readSensorConfigsFromFile(rootFilePath, type, configName); for(String sensorType : configs.keySet()) { byte[] configData = configs.get(sensorType); callback.apply(sensorType, configData); } } ``` which could be called from this case via `writeSensorConfigs(PARSER, configName, (sensorType, configData) -> writeSensorParserConfigToZookeeper(sensorType, configData, client));` Take the above as a very rough suggestion and you can feel to abstract it however you wish.
---