This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a7a1cd52f Don't replace environment variables and system properties 
in get table configs REST API (#14002)
4a7a1cd52f is described below

commit 4a7a1cd52fbf6b176fdfbd52872c3acdd763f50e
Author: Yash Mayya <yash.ma...@gmail.com>
AuthorDate: Thu Sep 19 02:07:04 2024 +0530

    Don't replace environment variables and system properties in get table 
configs REST API (#14002)
---
 .../pinot/common/metadata/ZKMetadataProvider.java  | 78 +++++++++++++++++++---
 .../api/resources/PinotTableRestletResource.java   |  4 +-
 .../api/resources/TableConfigsRestletResource.java |  4 +-
 .../helix/core/PinotHelixResourceManager.java      | 38 +++++++++--
 4 files changed, 106 insertions(+), 18 deletions(-)

diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java
 
b/pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java
index faf9b6799c..588b9df026 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java
@@ -100,8 +100,8 @@ public class ZKMetadataProvider {
   public static boolean setDatabaseConfig(ZkHelixPropertyStore<ZNRecord> 
propertyStore, DatabaseConfig databaseConfig) {
     String databaseName = databaseConfig.getDatabaseName();
     ZNRecord databaseConfigZNRecord = toZNRecord(databaseConfig);
-    return 
propertyStore.set(constructPropertyStorePathForDatabaseConfig(databaseName), 
databaseConfigZNRecord,
-        -1, AccessOption.PERSISTENT);
+    return 
propertyStore.set(constructPropertyStorePathForDatabaseConfig(databaseName), 
databaseConfigZNRecord, -1,
+        AccessOption.PERSISTENT);
   }
 
   /**
@@ -441,14 +441,31 @@ public class ZKMetadataProvider {
 
   @Nullable
   public static DatabaseConfig 
getDatabaseConfig(ZkHelixPropertyStore<ZNRecord> propertyStore, String 
databaseName) {
-    return 
toDatabaseConfig(propertyStore.get(constructPropertyStorePathForDatabaseConfig(databaseName),
 null,
-        AccessOption.PERSISTENT));
+    return toDatabaseConfig(
+        
propertyStore.get(constructPropertyStorePathForDatabaseConfig(databaseName), 
null, AccessOption.PERSISTENT));
   }
 
+  /**
+   * Get the table config for the given table name with type. Any environment 
variables and system properties will be
+   * replaced with their actual values.
+   */
   @Nullable
   public static TableConfig getTableConfig(ZkHelixPropertyStore<ZNRecord> 
propertyStore, String tableNameWithType) {
+    return getTableConfig(propertyStore, tableNameWithType, true);
+  }
+
+  /**
+   * Get the table config for the given table name with type
+   *
+   * @param tableNameWithType Table name with type
+   * @param replaceVariables Whether to replace environment variables and 
system properties with their actual values
+   * @return Table config
+   */
+  @Nullable
+  public static TableConfig getTableConfig(ZkHelixPropertyStore<ZNRecord> 
propertyStore, String tableNameWithType,
+      boolean replaceVariables) {
     return 
toTableConfig(propertyStore.get(constructPropertyStorePathForResourceConfig(tableNameWithType),
 null,
-        AccessOption.PERSISTENT));
+        AccessOption.PERSISTENT), replaceVariables);
   }
 
   /**
@@ -467,14 +484,54 @@ public class ZKMetadataProvider {
     return ImmutablePair.of(tableConfig, tableConfigStat.getVersion());
   }
 
+  /**
+   * Get the offline table config for the given table name. Any environment 
variables and system properties will be
+   * replaced with their actual values.
+   *
+   * @param tableName Table name with or without type suffix
+   * @return Table config
+   */
   @Nullable
   public static TableConfig 
getOfflineTableConfig(ZkHelixPropertyStore<ZNRecord> propertyStore, String 
tableName) {
-    return getTableConfig(propertyStore, 
TableNameBuilder.OFFLINE.tableNameWithType(tableName));
+    return getOfflineTableConfig(propertyStore, tableName, true);
   }
 
+  /**
+   * Get the offline table config for the given table name.
+   *
+   * @param tableName Table name with or without type suffix
+   * @param replaceVariables Whether to replace environment variables and 
system properties with their actual values
+   * @return Table config
+   */
+  @Nullable
+  public static TableConfig 
getOfflineTableConfig(ZkHelixPropertyStore<ZNRecord> propertyStore, String 
tableName,
+      boolean replaceVariables) {
+    return getTableConfig(propertyStore, 
TableNameBuilder.OFFLINE.tableNameWithType(tableName), replaceVariables);
+  }
+
+  /**
+   * Get the realtime table config for the given table name. Any environment 
variables and system properties will be
+   * replaced with their actual values.
+   *
+   * @param tableName Table name with or without type suffix
+   * @return Table config
+   */
   @Nullable
   public static TableConfig 
getRealtimeTableConfig(ZkHelixPropertyStore<ZNRecord> propertyStore, String 
tableName) {
-    return getTableConfig(propertyStore, 
TableNameBuilder.REALTIME.tableNameWithType(tableName));
+    return getRealtimeTableConfig(propertyStore, tableName, true);
+  }
+
+  /**
+   * Get the realtime table config for the given table name.
+   *
+   * @param tableName Table name with or without type suffix
+   * @param replaceVariables Whether to replace environment variables and 
system properties with their actual values
+   * @return Table config
+   */
+  @Nullable
+  public static TableConfig 
getRealtimeTableConfig(ZkHelixPropertyStore<ZNRecord> propertyStore, String 
tableName,
+      boolean replaceVariables) {
+    return getTableConfig(propertyStore, 
TableNameBuilder.REALTIME.tableNameWithType(tableName), replaceVariables);
   }
 
   public static List<TableConfig> 
getAllTableConfigs(ZkHelixPropertyStore<ZNRecord> propertyStore) {
@@ -502,12 +559,17 @@ public class ZKMetadataProvider {
 
   @Nullable
   private static TableConfig toTableConfig(@Nullable ZNRecord znRecord) {
+    return toTableConfig(znRecord, true);
+  }
+
+  @Nullable
+  private static TableConfig toTableConfig(@Nullable ZNRecord znRecord, 
boolean replaceVariables) {
     if (znRecord == null) {
       return null;
     }
     try {
       TableConfig tableConfig = TableConfigUtils.fromZNRecord(znRecord);
-      return 
ConfigUtils.applyConfigWithEnvVariablesAndSystemProperties(tableConfig);
+      return replaceVariables ? 
ConfigUtils.applyConfigWithEnvVariablesAndSystemProperties(tableConfig) : 
tableConfig;
     } catch (Exception e) {
       LOGGER.error("Caught exception while creating table config from 
ZNRecord: {}", znRecord.getId(), e);
       return null;
diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
index dee89efd64..c8e072db86 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
@@ -381,14 +381,14 @@ public class PinotTableRestletResource {
 
       if ((tableTypeStr == null || 
TableType.OFFLINE.name().equalsIgnoreCase(tableTypeStr))
           && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
-        TableConfig tableConfig = 
_pinotHelixResourceManager.getOfflineTableConfig(tableName);
+        TableConfig tableConfig = 
_pinotHelixResourceManager.getOfflineTableConfig(tableName, false);
         Preconditions.checkNotNull(tableConfig);
         ret.set(TableType.OFFLINE.name(), tableConfig.toJsonNode());
       }
 
       if ((tableTypeStr == null || 
TableType.REALTIME.name().equalsIgnoreCase(tableTypeStr))
           && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
-        TableConfig tableConfig = 
_pinotHelixResourceManager.getRealtimeTableConfig(tableName);
+        TableConfig tableConfig = 
_pinotHelixResourceManager.getRealtimeTableConfig(tableName, false);
         Preconditions.checkNotNull(tableConfig);
         ret.set(TableType.REALTIME.name(), tableConfig.toJsonNode());
       }
diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableConfigsRestletResource.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableConfigsRestletResource.java
index a1e2f74fb7..ea21f2ce46 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableConfigsRestletResource.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableConfigsRestletResource.java
@@ -156,8 +156,8 @@ public class TableConfigsRestletResource {
     try {
       tableName = DatabaseUtils.translateTableName(tableName, headers);
       Schema schema = _pinotHelixResourceManager.getTableSchema(tableName);
-      TableConfig offlineTableConfig = 
_pinotHelixResourceManager.getOfflineTableConfig(tableName);
-      TableConfig realtimeTableConfig = 
_pinotHelixResourceManager.getRealtimeTableConfig(tableName);
+      TableConfig offlineTableConfig = 
_pinotHelixResourceManager.getOfflineTableConfig(tableName, false);
+      TableConfig realtimeTableConfig = 
_pinotHelixResourceManager.getRealtimeTableConfig(tableName, false);
       TableConfigs config = new TableConfigs(tableName, schema, 
offlineTableConfig, realtimeTableConfig);
       return config.toJsonString();
     } catch (Exception e) {
diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
index 2b59109b89..a7e7037ee4 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
@@ -3077,25 +3077,51 @@ public class PinotHelixResourceManager {
   }
 
   /**
-   * Get the offline table config for the given table name.
+   * Get the offline table config for the given table name. Any environment 
variables and system properties will be
+   * replaced with their actual values.
    *
    * @param tableName Table name with or without type suffix
    * @return Table config
    */
   @Nullable
   public TableConfig getOfflineTableConfig(String tableName) {
-    return ZKMetadataProvider.getOfflineTableConfig(_propertyStore, tableName);
+    return getOfflineTableConfig(tableName, true);
   }
 
   /**
-   * Get the realtime table config for the given table name.
+   * Get the offline table config for the given table name.
+   *
+   * @param tableName Table name with or without type suffix
+   * @param replaceVariables Whether to replace environment variables and 
system properties with their actual values
+   * @return Table config
+   */
+  @Nullable
+  public TableConfig getOfflineTableConfig(String tableName, boolean 
replaceVariables) {
+    return ZKMetadataProvider.getOfflineTableConfig(_propertyStore, tableName, 
replaceVariables);
+  }
+
+  /**
+   * Get the realtime table config for the given table name. Any environment 
variables and system properties will be
+   * replaced with their actual values.
    *
    * @param tableName Table name with or without type suffix
    * @return Table config
    */
   @Nullable
   public TableConfig getRealtimeTableConfig(String tableName) {
-    return ZKMetadataProvider.getRealtimeTableConfig(_propertyStore, 
tableName);
+    return getRealtimeTableConfig(tableName, true);
+  }
+
+  /**
+   * Get the realtime table config for the given table name.
+   *
+   * @param tableName Table name with or without type suffix
+   * @param replaceVariables Whether to replace environment variables and 
system properties with their actual values
+   * @return Table config
+   */
+  @Nullable
+  public TableConfig getRealtimeTableConfig(String tableName, boolean 
replaceVariables) {
+    return ZKMetadataProvider.getRealtimeTableConfig(_propertyStore, 
tableName, replaceVariables);
   }
 
   /**
@@ -3422,8 +3448,8 @@ public class PinotHelixResourceManager {
    * @return List of untagged online server instances.
    */
   public List<String> getOnlineUnTaggedServerInstanceList() {
-    List<String> instanceListWithoutTags = 
HelixHelper.getInstancesWithoutTag(_helixZkManager,
-        Helix.UNTAGGED_SERVER_INSTANCE);
+    List<String> instanceListWithoutTags =
+        HelixHelper.getInstancesWithoutTag(_helixZkManager, 
Helix.UNTAGGED_SERVER_INSTANCE);
     List<String> liveInstances = 
_helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
 
     instanceListWithoutTags.retainAll(liveInstances);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to