noob-se7en commented on code in PR #18411:
URL: https://github.com/apache/pinot/pull/18411#discussion_r3180975298


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/resources/DeprecatedTableConfigValidationUtilsTest.java:
##########
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.controller.api.resources;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
+
+
+public class DeprecatedTableConfigValidationUtilsTest {
+
+  @Test
+  public void testRejectsDeprecatedConfigsWithArrayAndMapPaths()
+      throws Exception {
+    JsonNode tableConfigJson = JsonUtils.stringToJsonNode("{"
+        + 
"\"segmentsConfig\":{\"segmentPushType\":\"APPEND\",\"minimizeDataMovement\":false},"
+        + 
"\"tableIndexConfig\":{\"createInvertedIndexDuringSegmentGeneration\":false},"
+        + "\"fieldConfigList\":[{\"name\":\"c1\",\"indexType\":\"INVERTED\"}],"
+        + 
"\"instanceAssignmentConfigMap\":{\"CONSUMING\":{\"replicaGroupPartitionConfig\":"
+        + "{\"minimizeDataMovement\":false}}}}");
+
+    IllegalStateException e = expectThrows(IllegalStateException.class,
+        () -> 
DeprecatedTableConfigValidationUtils.validateNoDeprecatedConfigs(tableConfigJson,
 "realtime"));
+    
assertTrue(e.getMessage().contains("realtime.segmentsConfig.segmentPushType"));
+    
assertTrue(e.getMessage().contains("realtime.segmentsConfig.minimizeDataMovement"));
+    
assertTrue(e.getMessage().contains("realtime.tableIndexConfig.createInvertedIndexDuringSegmentGeneration"));
+    
assertTrue(e.getMessage().contains("realtime.fieldConfigList[0].indexType"));
+    assertTrue(
+        
e.getMessage().contains("realtime.instanceAssignmentConfigMap.CONSUMING.replicaGroupPartitionConfig"
+            + ".minimizeDataMovement"));

Review Comment:
   `DEPRECATED_CONFIG_RULES` has 17 entries; this test asserts on 5. the other 
12 (`segmentPush*`, `replicasPerPartition`, `streamConfigs`, all `upsert*` / 
`dedup*` flags, etc.) have no unit-level coverage. a `@DataProvider` over the 
rule table would track the list 1:1.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableConfigsRestletResource.java:
##########
@@ -461,19 +469,29 @@ public String validateConfig(String tableConfigsStr,
       @QueryParam("validationTypesToSkip") @Nullable String typesToSkip, 
@Context HttpHeaders httpHeaders,
       @Context Request request) {
     Pair<TableConfigs, Map<String, Object>> tableConfigsAndUnrecognizedProps;
+    JsonNode tableConfigsJson;
     try {
       tableConfigsAndUnrecognizedProps =
           JsonUtils.stringToObjectAndUnrecognizedProperties(tableConfigsStr, 
TableConfigs.class);
+      tableConfigsJson = JsonUtils.stringToJsonNode(tableConfigsStr);
     } catch (IOException e) {
       throw new ControllerApplicationException(LOGGER,
           String.format("Invalid TableConfigs json string: %s. Reason: %s", 
tableConfigsStr, e.getMessage()),
           Response.Status.BAD_REQUEST, e);
     }
     String databaseName = 
DatabaseUtils.extractDatabaseFromHttpHeaders(httpHeaders);
     TableConfigs tableConfigs = tableConfigsAndUnrecognizedProps.getLeft();
-    validateConfig(tableConfigs, databaseName, typesToSkip);
-    String rawTableName = 
DatabaseUtils.translateTableName(tableConfigs.getTableName(), databaseName);
-    tableConfigs.setTableName(rawTableName);
+    String rawTableName;
+    try {
+      validateNoDeprecatedCreateConfigs(tableConfigs, tableConfigsJson, 
databaseName);
+      validateConfig(tableConfigs, databaseName, typesToSkip);
+      rawTableName = 
DatabaseUtils.translateTableName(tableConfigs.getTableName(), databaseName);
+      tableConfigs.setTableName(rawTableName);
+    } catch (Exception e) {
+      throw new ControllerApplicationException(LOGGER,
+          String.format("Invalid TableConfigs json string: %s. Reason: %s", 
tableConfigsStr, e.getMessage()),

Review Comment:
   the new try/catch wraps every validation failure with 
`String.format("Invalid TableConfigs json string: %s ...", tableConfigsStr, 
...)` — bloats the response/log with the full input, and `String.format` in 
exception messages is discouraged per #14404. `addConfig` at L212 already uses 
`"Invalid TableConfigs. " + e.getMessage()` — match that here.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/DeprecatedTableConfigValidationUtils.java:
##########
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.controller.api.resources;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nullable;
+
+
+/**
+ * Validates raw table-config JSON for deprecated properties that must not be 
accepted on table creation paths.
+ *
+ * <p>This utility operates on the input JSON instead of the deserialized 
{@code TableConfig} so it can reject
+ * explicitly provided deprecated keys even when they carry default or false-y 
values.</p>
+ */
+public final class DeprecatedTableConfigValidationUtils {
+  private DeprecatedTableConfigValidationUtils() {
+  }
+
+  private static final String WILDCARD = "*";
+
+  private static final List<DeprecatedConfigRule> DEPRECATED_CONFIG_RULES = 
List.of(
+      new DeprecatedConfigRule("Use 
'ingestionConfig.batchIngestionConfig.segmentIngestionFrequency' instead.",
+          "segmentsConfig", "segmentPushFrequency"),
+      new DeprecatedConfigRule("Use 
'ingestionConfig.batchIngestionConfig.segmentIngestionType' instead.",
+          "segmentsConfig", "segmentPushType"),
+      new DeprecatedConfigRule("Use 'segmentsConfig.replication' instead.", 
"segmentsConfig", "replicasPerPartition"),
+      new DeprecatedConfigRule("Use 'segmentAssignmentConfigMap' instead.", 
"segmentsConfig",
+          "segmentAssignmentStrategy"),
+      new DeprecatedConfigRule("Use 'segmentAssignmentConfigMap' instead.", 
"segmentsConfig",
+          "replicaGroupStrategyConfig"),
+      new DeprecatedConfigRule("Use 'instanceAssignmentConfigMap' instead.", 
"segmentsConfig", "minimizeDataMovement"),
+      new DeprecatedConfigRule("Use 
'ingestionConfig.streamIngestionConfig.streamConfigMaps' instead.",
+          "tableIndexConfig", "streamConfigs"),
+      new DeprecatedConfigRule("Use 'tableIndexConfig.jsonIndexConfigs' 
instead.", "tableIndexConfig",
+          "jsonIndexColumns"),
+      new DeprecatedConfigRule("Remove this field; it is ignored.", 
"tableIndexConfig",
+          "createInvertedIndexDuringSegmentGeneration"),
+      new DeprecatedConfigRule("Use 'routing.segmentPrunerTypes' and 
'routing.instanceSelectorType' instead.",
+          "routing", "routingTableBuilderName"),
+      new DeprecatedConfigRule("Use 'fieldConfigList[].indexTypes' instead.", 
"fieldConfigList", WILDCARD,
+          "indexType"),
+      new DeprecatedConfigRule("Use 'upsertConfig.snapshot' instead.", 
"upsertConfig", "enableSnapshot"),
+      new DeprecatedConfigRule("Use 'upsertConfig.preload' instead.", 
"upsertConfig", "enablePreload"),
+      new DeprecatedConfigRule(
+          "Use 
'ingestionConfig.streamIngestionConfig.parallelSegmentConsumptionPolicy' 
instead.",
+          "upsertConfig", "allowPartialUpsertConsumptionDuringCommit"),
+      new DeprecatedConfigRule("Use 'dedupConfig.preload' instead.", 
"dedupConfig", "enablePreload"),
+      new DeprecatedConfigRule(
+          "Use 
'ingestionConfig.streamIngestionConfig.parallelSegmentConsumptionPolicy' 
instead.",
+          "dedupConfig", "allowDedupConsumptionDuringCommit"),
+      new DeprecatedConfigRule("Remove this field; it will be removed in a 
future release.",
+          "instanceAssignmentConfigMap", WILDCARD, 
"replicaGroupPartitionConfig", "minimizeDataMovement"));
+
+  public static void validateNoDeprecatedConfigs(JsonNode tableConfigJson) {
+    validateNoDeprecatedConfigs(tableConfigJson, null);
+  }
+
+  public static void validateNoDeprecatedConfigs(JsonNode tableConfigJson, 
@Nullable String rootPathPrefix) {
+    List<String> violations = new ArrayList<>();
+    for (DeprecatedConfigRule deprecatedConfigRule : DEPRECATED_CONFIG_RULES) {
+      deprecatedConfigRule.collectMatches(tableConfigJson, rootPathPrefix, 
violations);
+    }
+    if (!violations.isEmpty()) {
+      throw new IllegalStateException(

Review Comment:
   input-validation should throw `IllegalArgumentException`, not 
`IllegalStateException`. doesn't change wire behavior (controller catches 
`Exception` and rewraps), but a typed `catch` upstream would be misleading.



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to