jhsenjaliya commented on a change in pull request #3236:
URL: https://github.com/apache/gobblin/pull/3236#discussion_r646205907



##########
File path: 
gobblin-utility/src/main/java/org/apache/gobblin/util/ConfigUtils.java
##########
@@ -569,4 +608,124 @@ public static Config resolveEncrypted(Config config, 
Optional<String> encConfigP
     }
     return ConfigFactory.parseMap(tmpMap).withFallback(config);
   }
+
+  /**
+   *
+   * @param config
+   * @return ConfigObject ( config in tree ) of the {@link 
ConfigUtils#GOBBLIN_SYNC_SYSTEMS_KEY}
+   */
+  public static ConfigObject getAllSystemConfig(Config config) {
+    return (config.hasPath(GOBBLIN_SYNC_SYSTEMS_KEY) ? 
config.getObject(GOBBLIN_SYNC_SYSTEMS_KEY) : getInstance().root() );
+  }
+
+  /**
+   *
+   * @param config at path: {@link ConfigUtils#GOBBLIN_SYNC_SYSTEMS_KEY}
+   * @return map of system name to that system's config tree for all the 
systems that has security enabled
+   */
+  public static Map<String, ConfigObject> getAllSecureSystems(Config config) {
+    ConfigObject allSysConfig = getAllSystemConfig(config);
+    Map<String, ConfigObject> secureSystems = new HashMap<>();
+
+    if (allSysConfig == null) return secureSystems;
+
+    for (String systemName : allSysConfig.keySet()) {
+      ConfigObject sysConfig = allSysConfig.atPath(systemName).root();
+      sysConfig.get(IS_SECURE_KEY);
+      if (ConfigUtils.getBoolean(sysConfig.toConfig(), IS_SECURE_KEY, false)) {
+        secureSystems.put(systemName, sysConfig);
+      }
+    }
+    return secureSystems;
+  }
+
+  /**
+   *
+   * @param config at path: {@link ConfigUtils#GOBBLIN_SYNC_SYSTEMS_KEY}
+   * @return multiple map of system name and its all config files regardless 
of the component.
+   */
+  public static Multimap<String, String> getAllSystemConfigFiles(Config 
config) {
+
+    Multimap<String, String> allSysConfFiles = LinkedHashMultimap.create();
+
+    getAllSystemConfig(config).entrySet();
+    ConfigObject allSysConfig = getAllSystemConfig(config);
+
+    if (allSysConfig == null) return allSysConfFiles;
+
+    for (Map.Entry<String, ConfigValue> sysConfig : allSysConfig.entrySet()) {
+
+      if (sysConfig.getValue().valueType().equals(ConfigValueType.OBJECT)) {
+        ConfigObject allComponentConfigs = (ConfigObject) sysConfig.getValue();
+        for (Map.Entry<String, ConfigValue> componentConfig : 
allComponentConfigs.entrySet()) {
+          if 
(componentConfig.getValue().valueType().equals(ConfigValueType.OBJECT)) {
+            ConfigObject componentConfigValue = (ConfigObject) 
componentConfig.getValue();
+            Config configValue = componentConfigValue.toConfig();
+            if (configValue.hasPath(GOBBLIN_SYNC_SYSTEM_CONFIG_FILES_KEY)) {
+              
configValue.getList(GOBBLIN_SYNC_SYSTEM_CONFIG_FILES_KEY).forEach(item -> 
allSysConfFiles.put(sysConfig.getKey(), item.unwrapped().toString()));
+            }
+          }
+        }
+      }
+    }
+    return allSysConfFiles;
+  }
+
+  /**
+   *
+   * @param config at path: {@link ConfigUtils#GOBBLIN_SYNC_SYSTEMS_KEY}
+   * @return map of all system -> config for which the token management {@link 
ConfigUtils#IS_TOKEN_MGMT_ENABLED_KEY} is enabled.
+   */
+  public static Map<String, Config> getAllSecureHiveSystems(Config config){
+    Map<String, Config> secureSystems = new HashMap<>();
+
+    for (String systemName : 
config.getObject(GOBBLIN_SYNC_SYSTEMS_KEY).keySet()){
+      Config sysConfig = 
config.getConfig(GOBBLIN_SYNC_SYSTEMS_KEY).getConfig(systemName);
+      if(ConfigUtils.getBoolean(sysConfig, IS_SECURE_KEY, false) && 
ConfigUtils.getBoolean(sysConfig, IS_TOKEN_MGMT_ENABLED_KEY, false) && 
sysConfig.hasPath(HIVE_SYSTEM_KEY)){
+        secureSystems.put(systemName, sysConfig);
+      }
+    }
+    return secureSystems;
+  }
+
+  /**
+   *
+   * @param metastoreURI for which we need to find system and its config
+   * @param config at path: {@link ConfigUtils#GOBBLIN_SYNC_SYSTEMS_KEY}
+   * @return map of system name -> config paths for the given metastoreURI
+   */
+  public static Multimap<String, String> getSystemConfigForMetastore(String 
metastoreURI, Config config) {
+    if (config == null) {
+      config = getInstance();
+    }
+
+    Multimap<String, String> sysConfFiles = LinkedHashMultimap.create();
+
+    ConfigObject allSysConfig = getAllSystemConfig(config);
+
+    if (allSysConfig == null) return sysConfFiles;
+
+    for (Map.Entry<String, ConfigValue> sysConfig : allSysConfig.entrySet()) {
+
+      if (sysConfig.getValue().valueType().equals(ConfigValueType.OBJECT)) {
+        ConfigObject allComponentConfigs = (ConfigObject) sysConfig.getValue();

Review comment:
       this makes the traversing possible, only `ConfigObject` provides the 
entrySet method which `ConfigValue` does not. I think there can be other ways 
to obtain `ConfigObject` out of `ConfigValue` as well.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to