You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "xiangfu0 (via GitHub)" <gi...@apache.org> on 2025/11/08 01:38:23 UTC

[PR] Migrate tests and connector to PinotAdminClient [pinot]

xiangfu0 opened a new pull request, #17167:
URL: https://github.com/apache/pinot/pull/17167

   add missing admin clients (logical table, cluster, query workload); 
   replace ControllerRequestClient usages where possible; 
   add pinot-java-client dep in Flink connector


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #17167:
URL: https://github.com/apache/pinot/pull/17167#issuecomment-3505623039

   ### :warning: Unsupported file format
   <details><summary>Upload processing failed due to unsupported file format. Please review the parser error message:</summary>
   <pre><code class="language-python">Error parsing JUnit XML in /home/runner/work/pinot/pinot/pinot-query-runtime/target/surefire-reports/TEST-org.apache.pinot.query.runtime.queries.ResourceBasedQueriesTest.xml at 181:1069
   
   Caused by:
       RuntimeError: Error converting computed name to ValidatedString
       
       Caused by:
           string is too long</code></pre>
   </details>
   
   For more help, visit our [troubleshooting guide](https://docs.codecov.com/docs/test-analytics#troubleshooting).


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041201894


##########
pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTest.java:
##########
@@ -1166,26 +1169,25 @@ protected long getLongCellValue(JsonNode jsonNode, int colIndex, int rowIndex) {
 
   protected JsonNode getColumnIndexSize(String column)
       throws Exception {
-    return JsonUtils.stringToJsonNode(
-            sendGetRequest(_controllerRequestURLBuilder.forTableAggregateMetadata(getTableName(), List.of(column))))
-        .get("columnIndexSizeMap").get(column);
+    TableMetadataInfo metadata = getOrCreateAdminClient().getTableClient()
+        .getAggregateMetadata(getTableName(), String.join(",", List.of(column)));
+    return JsonUtils.objectToJsonNode(metadata).get("columnIndexSizeMap").get(column);
   }
 
   /**
    * Get all segment names for a given tableName and tableType.
    */
   protected List<String> getSegmentNames(String tableName, @Nullable String tableType)
       throws Exception {
-    return getControllerRequestClient().listSegments(tableName, tableType, true);
+    return getOrCreateAdminClient().getSegmentClient().listSegments(tableName, tableType, true);
   }
 
   protected List<ValidDocIdsMetadataInfo> getValidDocIdsMetadata(String tableNameWithType,
       ValidDocIdsType validDocIdsType)
       throws Exception {
 
-    StringBuilder urlBuilder = new StringBuilder(
-        _controllerRequestURLBuilder.forValidDocIdsMetadata(tableNameWithType, validDocIdsType.toString()));
-    String responseString = sendGetRequest(urlBuilder.toString());
+    String responseString = getOrCreateAdminClient().getTableClient()
+        .getValidDocIdsMetadata(tableNameWithType, validDocIdsType.toString());

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/TableViewsTest.java:
##########
@@ -166,15 +188,22 @@ public void testHybridTableState(String state)
 
   private TableViews.TableView getTableView(String tableName, String view, String tableType)
       throws Exception {
-    return JsonUtils.stringToObject(
-        sendGetRequest(DEFAULT_INSTANCE.getControllerRequestURLBuilder().forTableView(tableName, view, tableType)),
-        TableViews.TableView.class);
+    PinotAdminClient adminClient = getOrCreateAdminClient();
+    return adminClient.getTableClient().getTableView(tableName, view, tableType, TableViews.TableView.class);

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039172522


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -69,17 +76,32 @@ public String getSchemasInfo()
   }
 
   /**
-   * Gets a specific schema by name.
+   * Gets a specific schema as a JSON string.
    *
    * @param schemaName Name of the schema
    * @return Schema configuration as JSON string
    * @throws PinotAdminException If the request fails
    */
-  public String getSchema(String schemaName)
+  public String getSchemaString(String schemaName)
       throws PinotAdminException {
     JsonNode response = _transport.executeGet(_controllerAddress, "/schemas/" + schemaName, null, _headers);
     return response.toString();
   }
+  /**
+   * Gets a specific schema as a typed object.
+   * Prefer this method when you want to work with the Schema model directly.
+   * Use {@link #getSchemaString(String)} if you need the raw JSON.
+   *
+   * @param schemaName Name of the schema
+   * @return Pinot Schema object
+   * @throws PinotAdminException If the request fails
+   * @throws IOException If the response cannot be parsed as a Schema
+   */
+  public Schema getSchema(String schemaName)

Review Comment:
   Done - removed deprecated `getSchemaString()`. `getSchema()` returns JSON string, `getSchemaObject()` returns typed Schema.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -69,17 +76,32 @@ public String getSchemasInfo()
   }
 
   /**
-   * Gets a specific schema by name.
+   * Gets a specific schema as a JSON string.
    *
    * @param schemaName Name of the schema
    * @return Schema configuration as JSON string
    * @throws PinotAdminException If the request fails
    */
-  public String getSchema(String schemaName)
+  public String getSchemaString(String schemaName)

Review Comment:
   Done - `getSchema()` is the JSON string method (kept as-is), deprecated `getSchemaString()` removed.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039174565


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/http/PinotConnectionUtils.java:
##########
@@ -38,18 +38,23 @@ public final class PinotConnectionUtils {
   private PinotConnectionUtils() {
   }
 
-  public static Schema getSchema(ControllerRequestClient client, String tableName) {
+  public static Schema getSchema(PinotAdminClient client, String tableName) {
     try {
-      return client.getSchema(tableName);
+      return client.getSchemaClient().getSchema(tableName);
     } catch (Exception e) {
       throw new RuntimeException(String.format("Failed to get table schema %s from Pinot controller", tableName), e);
     }
   }
 
-  public static TableConfig getTableConfig(ControllerRequestClient client, String tableName, String tableType) {
+  public static TableConfig getTableConfig(PinotAdminClient client, String tableName, String tableType) {
     TableConfig tableConfig;
     try {
-      tableConfig = client.getTableConfig(tableName, TableType.valueOf(tableType));
+      String configJson = client.getTableClient().getTableConfig(tableName, tableType);

Review Comment:
   Done - PinotTableAdminClient has getTableConfigObject() returning typed TableConfig.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,12 +77,11 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
-    TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
-    srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
-    execEnv.execute();
+    try (PinotAdminClient client = new PinotAdminClient("localhost:9000")) {
+      Schema schema = client.getSchemaClient().getSchema("starbucksStores");
+      TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");

Review Comment:
   Done - PinotConnectionUtils removed; FlinkQuickStart uses PinotAdminClient directly.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java:
##########
@@ -351,10 +352,19 @@ private TableView getTableIdealState(String tableNameOptType, @Nullable TableTyp
   private TableView getTableExternalView(String tableNameOptType, @Nullable TableType tableType) {
     TableView tableView = new TableView();
     if (tableType == null || tableType == TableType.OFFLINE) {
-      tableView._offline = getExternalView(tableNameOptType, TableType.OFFLINE);
+      Map<String, Map<String, String>> external = getExternalView(tableNameOptType, TableType.OFFLINE);
+      if (external == null || external.isEmpty()) {
+        // Fallback to ideal state if external view is not yet materialized.
+        external = getIdealState(tableNameOptType, TableType.OFFLINE);

Review Comment:
   Acknowledged - TableViews controller code is unchanged in this PR (only a cosmetic blank line). No idealstate fallback was added.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java:
##########
@@ -351,10 +352,19 @@ private TableView getTableIdealState(String tableNameOptType, @Nullable TableTyp
   private TableView getTableExternalView(String tableNameOptType, @Nullable TableType tableType) {
     TableView tableView = new TableView();
     if (tableType == null || tableType == TableType.OFFLINE) {
-      tableView._offline = getExternalView(tableNameOptType, TableType.OFFLINE);
+      Map<String, Map<String, String>> external = getExternalView(tableNameOptType, TableType.OFFLINE);
+      if (external == null || external.isEmpty()) {
+        // Fallback to ideal state if external view is not yet materialized.
+        external = getIdealState(tableNameOptType, TableType.OFFLINE);
+      }
+      tableView._offline = external;
     }
     if (tableType == null || tableType == TableType.REALTIME) {
-      tableView._realtime = getExternalView(tableNameOptType, TableType.REALTIME);
+      Map<String, Map<String, String>> external = getExternalView(tableNameOptType, TableType.REALTIME);
+      if (external == null || external.isEmpty()) {
+        external = getIdealState(tableNameOptType, TableType.REALTIME);

Review Comment:
   Acknowledged - no idealstate fallback in the current code.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/http/PinotConnectionUtils.java:
##########
@@ -38,18 +38,23 @@ public final class PinotConnectionUtils {
   private PinotConnectionUtils() {
   }
 
-  public static Schema getSchema(ControllerRequestClient client, String tableName) {
+  public static Schema getSchema(PinotAdminClient client, String tableName) {

Review Comment:
   Done - PinotConnectionUtils removed.



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotIngestionRestletResourceStatelessTest.java:
##########
@@ -100,13 +102,14 @@ public void testIngestEndpoint()
     Map<String, String> batchConfigMap = new HashMap<>();
     batchConfigMap.put(BatchConfigProperties.INPUT_FORMAT, "csv");
     batchConfigMap.put(String.format("%s.delimiter", BatchConfigProperties.RECORD_READER_PROP_PREFIX), "|");
-    sendHttpPost(_controllerRequestURLBuilder.forIngestFromFile(TABLE_NAME_WITH_TYPE, batchConfigMap));
+    sendHttpPost(adminClient.getTableClient().buildIngestFromFileUrl(TABLE_NAME_WITH_TYPE, batchConfigMap));

Review Comment:
   Done - PinotFileIngestClient created with ingestFromFile/ingestFromUri/postFile/postString methods.



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotFileUploadTest.java:
##########
@@ -58,8 +58,9 @@ public void setUp()
   @Test
   public void testUploadBogusData()
       throws Exception {
+    String uploadUrl = TEST_INSTANCE.getAdminClient().getSegmentUploadUrl();
     try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
-      HttpPost httpPost = new HttpPost(TEST_INSTANCE.getControllerRequestURLBuilder().forDataFileUpload());
+      HttpPost httpPost = new HttpPost(uploadUrl);

Review Comment:
   Done - PinotFileIngestClient already created.



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotInstanceRestletResourceTest.java:
##########
@@ -274,23 +271,20 @@ public void instanceRetagServerDeficiencyTest()
   }
 
   private Map<String, List<String>> getCurrentInstanceTagsMap()
-      throws IOException {
-    String listInstancesUrl = _urlBuilder.forInstanceList();
-    JsonNode response = JsonUtils.stringToJsonNode(sendGetRequest(listInstancesUrl));
-    JsonNode instances = response.get("instances");
+      throws Exception {
+    PinotAdminClient adminClient = DEFAULT_INSTANCE.getOrCreateAdminClient();
+    List<String> instances = adminClient.getInstanceClient().listInstances();
     Map<String, List<String>> map = new HashMap<>(instances.size());
-    for (int i = 0; i < instances.size(); i++) {
-      String instance = instances.get(i).asText();
-      map.put(instance, getInstanceTags(instance));
+    for (String instance : instances) {
+      map.put(instance, getInstanceTags(adminClient, instance));
     }
     return map;
   }
 
-  private List<String> getInstanceTags(String instance)
-      throws IOException {
-    String getInstancesUrl = _urlBuilder.forInstance(instance);
+  private List<String> getInstanceTags(PinotAdminClient adminClient, String instance)
+      throws Exception {
     List<String> tags = new ArrayList<>();
-    for (JsonNode tag : JsonUtils.stringToJsonNode(sendGetRequest(getInstancesUrl)).get("tags")) {
+    for (JsonNode tag : JsonUtils.stringToJsonNode(adminClient.getInstanceClient().getInstance(instance)).get("tags")) {

Review Comment:
   Done - getInstanceTags(String) already added to PinotInstanceAdminClient.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041146232


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -940,16 +949,10 @@ protected void waitForRebalanceToComplete(String rebalanceJobId, long timeoutMs)
   protected void waitForTableEVISConverge(String tableName, long timeoutMs) {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forIdealState(tableName);
-        SimpleHttpResponse httpResponse =
-            HttpClient.wrapAndThrowHttpException(getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null));
         TableViews.TableView idealState =
-            JsonUtils.stringToObject(httpResponse.getResponse(), TableViews.TableView.class);
-
-        requestUrl = getControllerRequestURLBuilder().forExternalView(tableName);
-        httpResponse = getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null);
+            getOrCreateAdminClient().getTableClient().getIdealState(tableName, TableViews.TableView.class);

Review Comment:
   getIdealState() should return TableView directly



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -940,16 +949,10 @@ protected void waitForRebalanceToComplete(String rebalanceJobId, long timeoutMs)
   protected void waitForTableEVISConverge(String tableName, long timeoutMs) {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forIdealState(tableName);
-        SimpleHttpResponse httpResponse =
-            HttpClient.wrapAndThrowHttpException(getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null));
         TableViews.TableView idealState =
-            JsonUtils.stringToObject(httpResponse.getResponse(), TableViews.TableView.class);
-
-        requestUrl = getControllerRequestURLBuilder().forExternalView(tableName);
-        httpResponse = getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null);
+            getOrCreateAdminClient().getTableClient().getIdealState(tableName, TableViews.TableView.class);
         TableViews.TableView externalView =
-            JsonUtils.stringToObject(httpResponse.getResponse(), TableViews.TableView.class);
+            getOrCreateAdminClient().getTableClient().getExternalView(tableName, TableViews.TableView.class);

Review Comment:
   getIdealState() should return TableView directly



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038808050


##########
pinot-connectors/pinot-flink-connector/src/test/java/org/apache/pinot/connector/flink/sink/PinotSinkIntegrationTest.java:
##########
@@ -133,17 +130,20 @@ public void testPinotSinkWrite()
   }
 
   private void verifySegments(int numSegments, int numTotalDocs)
-      throws IOException {
-    JsonNode segments = JsonUtils.stringToJsonNode(sendGetRequest(
-            _controllerRequestURLBuilder.forSegmentListAPI(OFFLINE_TABLE_NAME, TableType.OFFLINE.toString()))).get(0)
-        .get("OFFLINE");
+      throws Exception {
+    List<String> segments = getOrCreateAdminClient().getSegmentClient()

Review Comment:
   extract `getOrCreateAdminClient().getSegmentClient()` to local



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Add typed admin client APIs with response classes in pinot-common; migrate tests and connectors to PinotAdminClient [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3048418215


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/AbstractPinotAdminClient.java:
##########
@@ -0,0 +1,54 @@
+/**
+ * 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.client.admin;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Base class for controller admin clients backed by a shared {@link PinotAdminTransport}.
+ * Implementations are thread-safe as long as the parent {@link PinotAdminClient} remains open.
+ */
+abstract class AbstractPinotAdminClient {

Review Comment:
   (minor) We usually use `Base` prefix to represent base class
   
   It is a little bit confusing given `PInotAdminClient` doesn't implement it. Maybe `BaseServiceAdminClient`



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotBrokerAdminClient.java:
##########
@@ -0,0 +1,145 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+/**
+ * Client for broker-related administration operations.
+ */
+public class PinotBrokerAdminClient extends AbstractPinotAdminClient {

Review Comment:
   Consider removing the `Pinot` prefix, which seems quite redundant



##########
pinot-common/src/test/java/org/apache/pinot/util/TestUtils.java:
##########
@@ -151,6 +150,12 @@ public static void waitForCondition(SupplierWithException<Boolean> condition, lo
           }
         }
       }
+      try {
+        Thread.sleep(checkIntervalMs);
+      } catch (InterruptedException e) {
+        lastError = e;
+        break;
+      }

Review Comment:
   Why do we need this change?



##########
pinot-common/src/main/java/org/apache/pinot/common/response/BatchConfig.java:
##########
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.pinot.controller.api.resources;
+package org.apache.pinot.common.response;

Review Comment:
   Put them under a separate folder. Check if `restlet.resources` is a good candidate



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Add typed admin client APIs with response classes in pinot-common; migrate tests and connectors to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3048731987


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/AbstractPinotAdminClient.java:
##########
@@ -0,0 +1,54 @@
+/**
+ * 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.client.admin;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Base class for controller admin clients backed by a shared {@link PinotAdminTransport}.
+ * Implementations are thread-safe as long as the parent {@link PinotAdminClient} remains open.
+ */
+abstract class AbstractPinotAdminClient {

Review Comment:
   Done - renamed to `BaseServiceAdminClient`.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotBrokerAdminClient.java:
##########
@@ -0,0 +1,145 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+/**
+ * Client for broker-related administration operations.
+ */
+public class PinotBrokerAdminClient extends AbstractPinotAdminClient {

Review Comment:
   Done - removed `Pinot` prefix from all service admin clients (e.g. `BrokerAdminClient`, `TableAdminClient`, `SchemaAdminClient`, etc.). The main entry point `PinotAdminClient` keeps its name.



##########
pinot-common/src/main/java/org/apache/pinot/common/response/BatchConfig.java:
##########
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.pinot.controller.api.resources;
+package org.apache.pinot.common.response;

Review Comment:
   Done - moved all response classes to `org.apache.pinot.common.restlet.resources` package.



##########
pinot-common/src/test/java/org/apache/pinot/util/TestUtils.java:
##########
@@ -151,6 +150,12 @@ public static void waitForCondition(SupplierWithException<Boolean> condition, lo
           }
         }
       }
+      try {
+        Thread.sleep(checkIntervalMs);
+      } catch (InterruptedException e) {
+        lastError = e;
+        break;
+      }

Review Comment:
   Reverted - the TestUtils change was unintentional.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038978758


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/KafkaConsumingSegmentToBeMovedSummaryIntegrationTest.java:
##########
@@ -143,8 +143,8 @@ public void testConsumingSegmentSummary()
         .reduce(0L, (a, b) -> a + b.getTotalOffsetsToCatchUpAcrossAllConsumingSegments(), Long::sum), 57801);
 
     // set includeConsuming to false
-    response = sendPostRequest(
-        getControllerRequestURLBuilder().forTableRebalance(getTableName(), "REALTIME", true, false, false, false, -1));
+    response = getOrCreateAdminClient().getTableClient()

Review Comment:
   rebalanceTable method should return RebalanceResult class.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on PR #17167:
URL: https://github.com/apache/pinot/pull/17167#issuecomment-4192029052

   @copilot review


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3042406006


##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/ChangeTableState.java:
##########
@@ -36,71 +30,49 @@
 
 
 @CommandLine.Command(name = "ChangeTableState", mixinStandardHelpOptions = true)
-public class ChangeTableState extends AbstractBaseAdminCommand implements Command {
+public class ChangeTableState extends AbstractDatabaseBaseAdminCommand implements Command {
   private static final Logger LOGGER = LoggerFactory.getLogger(ChangeTableState.class);
 
-  @CommandLine.Option(names = {"-controllerHost"}, required = false, description = "host name for controller")
-  private String _controllerHost;
-
-  @CommandLine.Option(names = {"-controllerPort"}, required = false, description = "Port number for controller.")
-  private String _controllerPort = DEFAULT_CONTROLLER_PORT;
-
-  @CommandLine.Option(names = {"-controllerProtocol"}, required = false, description = "protocol for controller.")
-  private String _controllerProtocol = CommonConstants.HTTP_PROTOCOL;
-
   @CommandLine.Option(names = {"-tableName"}, required = true, description = "Table name to disable")
   private String _tableName;
 
+  @CommandLine.Option(names = {"-tableType"}, required = false,
+      description = "Table type (OFFLINE|REALTIME). Optional if tableName already has a type suffix.")
+  private TableType _tableType;
+
   @CommandLine.Option(names = {"-state"}, required = true, description = "Change Table State(enable|disable|drop)")
   private String _state;
 
-  @CommandLine.Option(names = {"-user"}, required = false, description = "Username for basic auth.")
-  private String _user;
-
-  @CommandLine.Option(names = {"-password"}, required = false, description = "Password for basic auth.")
-  private String _password;
-
-  @CommandLine.Option(names = {"-authToken"}, required = false, description = "Http auth token.")
-  private String _authToken;
-
-  @CommandLine.Option(names = {"-authTokenUrl"}, required = false, description = "Http auth token url.")
-  private String _authTokenUrl;
-
-  private AuthProvider _authProvider;
-
-  public ChangeTableState setAuthProvider(AuthProvider authProvider) {
-    _authProvider = authProvider;
-    return this;
-  }
-
   @Override
   public boolean execute()
       throws Exception {
     if (_controllerHost == null) {
       _controllerHost = NetUtils.getHostAddress();
     }
 
-    String stateValue = _state.toLowerCase();
+    String stateValue = _state.toLowerCase(Locale.ROOT);
     if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) {
       throw new IllegalArgumentException(
           "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop");
     }
-    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
-      URI uri = new URI(_controllerProtocol, null, _controllerHost, Integer.parseInt(_controllerPort),
-          URI_TABLES_PATH + _tableName, "state=" + stateValue, null);
-
-      HttpGet httpGet = new HttpGet(uri);
-      AuthProviderUtils.makeAuthHeaders(
-              AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user, _password))
-          .forEach(header -> httpGet.addHeader(header.getName(), header.getValue()));
-
-      try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
-        int status = response.getCode();
-        if (status != 200) {
-          String responseString = EntityUtils.toString(response.getEntity());
-          throw new HttpException("Failed to change table state, error: " + responseString);
-        }
+    String tableType = _tableType != null ? _tableType.name() : null;
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      switch (stateValue) {
+        case "enable":
+          adminClient.getTableClient().setTableState(_tableName, tableType, true);
+          break;
+        case "disable":
+          adminClient.getTableClient().setTableState(_tableName, tableType, false);
+          break;
+        case "drop":
+          adminClient.getTableClient().deleteTable(_tableName, tableType, null, null);
+          break;

Review Comment:
   `-tableType` is documented as optional when `-tableName` already includes a type suffix, but the controller `/tables/{tableName}/state` API requires the `type` query param. When `_tableType` is null, this sends no `type` and will fail with 400. Also, if callers pass a typed table name (e.g. `foo_OFFLINE`) and a `type`, the controller will append the suffix again (e.g. `foo_OFFLINE_OFFLINE`). Consider: (1) parsing `_tableName` to extract raw name + inferred type when `_tableType` is null, and (2) always passing the raw name in the path and the inferred/explicit type as the query param; or make `-tableType` required and remove the “optional” claim.



##########
pinot-connectors/pinot-flink-connector/README.md:
##########
@@ -57,9 +57,9 @@ ControllerRequestClient client = new ControllerRequestClient(
 ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
 
 // fetch Pinot schema
-Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+Schema schema = client.getSchemaClient().getSchemaObject("starbucksStores");
 // fetch Pinot table config
-TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "REALTIME");
+TableConfig tableConfig = client.getTableClient().getTableConfigObject("starbucksStores", "REALTIME");
 

Review Comment:
   Same issue as the offline quick-start snippet above: this example still uses `ControllerRequestClient` but calls `getSchemaClient()`/`getTableClient()` methods that exist on `PinotAdminClient`. Please switch the snippet to use `PinotAdminClient` so it compiles and matches the migrated code.



##########
pinot-connectors/pinot-flink-connector/README.md:
##########
@@ -36,9 +36,9 @@ ControllerRequestClient client = new ControllerRequestClient(
 ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
 
 // fetch Pinot schema
-Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+Schema schema = client.getSchemaClient().getSchemaObject("starbucksStores");
 // fetch Pinot table config
-TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
+TableConfig tableConfig = client.getTableClient().getTableConfigObject("starbucksStores", "OFFLINE");
 // create Flink Pinot Sink

Review Comment:
   The README snippet still constructs a `ControllerRequestClient`/`HttpClient`, but then calls `getSchemaClient()`/`getTableClient()` which are `PinotAdminClient` APIs. As written, this example won’t compile and doesn’t reflect the new recommended client. Update the snippet to instantiate `PinotAdminClient` (preferably with try-with-resources) and remove the `ControllerRequestClient` setup.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039361464


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotControllerAppConfigsTest.java:
##########
@@ -46,16 +45,15 @@ public void setUp()
   /**
    * Asserts that app configurations returned by the controller endpoint
    * are as expected.
-   * @throws IOException In case of exception
    */
   @Test
   public void testControllerAppConfigs()
-      throws IOException {
+      throws Exception {
     ControllerConf expectedControllerConf = TEST_INSTANCE.getControllerConfig();
     PinotAppConfigs expected = new PinotAppConfigs(expectedControllerConf);
 
-    String configsJson = ControllerTest.sendGetRequest(TEST_INSTANCE.getControllerRequestURLBuilder().forAppConfigs());
-    PinotAppConfigs actual = JsonUtils.stringToObject(configsJson, PinotAppConfigs.class);
+    PinotAppConfigs actual = TEST_INSTANCE.getOrCreateAdminClient().getClusterClient().getAppConfigs(

Review Comment:
   this getClusterClient().getAppConfigs() should return PinotAppConfigs, 
   PinotAppConfigs.class shouldn't be the argument



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3040980297


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotControllerAppConfigsTest.java:
##########
@@ -46,16 +45,15 @@ public void setUp()
   /**
    * Asserts that app configurations returned by the controller endpoint
    * are as expected.
-   * @throws IOException In case of exception
    */
   @Test
   public void testControllerAppConfigs()
-      throws IOException {
+      throws Exception {
     ControllerConf expectedControllerConf = TEST_INSTANCE.getControllerConfig();
     PinotAppConfigs expected = new PinotAppConfigs(expectedControllerConf);
 
-    String configsJson = ControllerTest.sendGetRequest(TEST_INSTANCE.getControllerRequestURLBuilder().forAppConfigs());
-    PinotAppConfigs actual = JsonUtils.stringToObject(configsJson, PinotAppConfigs.class);
+    PinotAppConfigs actual = TEST_INSTANCE.getOrCreateAdminClient().getClusterClient().getAppConfigs(

Review Comment:
   Done - getAppConfigs() now returns PinotAppConfigs directly. Removed the Class<T> overload.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041143665


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -911,24 +909,35 @@ private MetricFieldSpec constructNewMetric(FieldSpec.DataType dataType) {
     return new MetricFieldSpec(column, dataType);
   }
 
+  protected RebalanceResult triggerTableRebalance(RebalanceConfig rebalanceConfig, TableType tableType)
+      throws IOException, PinotAdminException {
+    Map<String, String> queryParams = new HashMap<>();
+    queryParams.put("type", tableType.toString());
+    String[] params = rebalanceConfig.toQueryString().split("&");
+    for (String param : params) {
+      String[] kv = param.split("=", 2);
+      if (kv.length == 2) {
+        queryParams.put(kv[0], kv[1]);
+      }
+    }
+    return getOrCreateAdminClient().getRebalanceClient()

Review Comment:
   rebalanceTable() should return `RebalanceResult` directly



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038774939


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -69,17 +76,32 @@ public String getSchemasInfo()
   }
 
   /**
-   * Gets a specific schema by name.
+   * Gets a specific schema as a JSON string.
    *
    * @param schemaName Name of the schema
    * @return Schema configuration as JSON string
    * @throws PinotAdminException If the request fails
    */
-  public String getSchema(String schemaName)
+  public String getSchemaString(String schemaName)
       throws PinotAdminException {
     JsonNode response = _transport.executeGet(_controllerAddress, "/schemas/" + schemaName, null, _headers);
     return response.toString();
   }
+  /**
+   * Gets a specific schema as a typed object.
+   * Prefer this method when you want to work with the Schema model directly.
+   * Use {@link #getSchemaString(String)} if you need the raw JSON.
+   *
+   * @param schemaName Name of the schema
+   * @return Pinot Schema object
+   * @throws PinotAdminException If the request fails
+   * @throws IOException If the response cannot be parsed as a Schema
+   */
+  public Schema getSchema(String schemaName)

Review Comment:
   rename this to getSchemaObject 



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038871736


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/http/PinotConnectionUtils.java:
##########
@@ -38,18 +38,23 @@ public final class PinotConnectionUtils {
   private PinotConnectionUtils() {
   }
 
-  public static Schema getSchema(ControllerRequestClient client, String tableName) {
+  public static Schema getSchema(PinotAdminClient client, String tableName) {

Review Comment:
   This method is not needed, just use PinotAdminClient



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038908845


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotInstanceRestletResourceTest.java:
##########
@@ -274,23 +271,20 @@ public void instanceRetagServerDeficiencyTest()
   }
 
   private Map<String, List<String>> getCurrentInstanceTagsMap()
-      throws IOException {
-    String listInstancesUrl = _urlBuilder.forInstanceList();
-    JsonNode response = JsonUtils.stringToJsonNode(sendGetRequest(listInstancesUrl));
-    JsonNode instances = response.get("instances");
+      throws Exception {
+    PinotAdminClient adminClient = DEFAULT_INSTANCE.getOrCreateAdminClient();
+    List<String> instances = adminClient.getInstanceClient().listInstances();
     Map<String, List<String>> map = new HashMap<>(instances.size());
-    for (int i = 0; i < instances.size(); i++) {
-      String instance = instances.get(i).asText();
-      map.put(instance, getInstanceTags(instance));
+    for (String instance : instances) {
+      map.put(instance, getInstanceTags(adminClient, instance));
     }
     return map;
   }
 
-  private List<String> getInstanceTags(String instance)
-      throws IOException {
-    String getInstancesUrl = _urlBuilder.forInstance(instance);
+  private List<String> getInstanceTags(PinotAdminClient adminClient, String instance)
+      throws Exception {
     List<String> tags = new ArrayList<>();
-    for (JsonNode tag : JsonUtils.stringToJsonNode(sendGetRequest(getInstancesUrl)).get("tags")) {
+    for (JsonNode tag : JsonUtils.stringToJsonNode(adminClient.getInstanceClient().getInstance(instance)).get("tags")) {

Review Comment:
   create a api to get instance tags and use it here



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038960801


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/TableRebalancePauselessIntegrationTest.java:
##########
@@ -186,9 +186,9 @@ public void testForceCommit(TableConfig tableConfig)
       // notice that this could get an HTTP 409 CONFLICT, when the test failed due to the timeout waiting on the table
       // to converge, and try to rebalance again here. So we need to cancel the original job first.
       sendDeleteRequest(

Review Comment:
   should create the api in rebalance client and use api call



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on PR #17167:
URL: https://github.com/apache/pinot/pull/17167#issuecomment-4191920428

   @copilot review


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039262422


##########
pinot-connectors/pinot-flink-connector/README.md:
##########
@@ -36,9 +36,9 @@ ControllerRequestClient client = new ControllerRequestClient(
 ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
 
 // fetch Pinot schema
-Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+Schema schema = client.getSchemaClient().getSchemaObject("starbucksStores");
 // fetch Pinot table config
-TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
+TableConfig tableConfig = client.getTableClient().getTableConfigObject("starbucksStores", "OFFLINE");

Review Comment:
   The README code snippet still instantiates a ControllerRequestClient, but then calls admin-client style APIs (getSchemaClient()/getTableClient()), which ControllerRequestClient doesn't have. Update the snippet to use PinotAdminClient (and ideally try-with-resources) so the example compiles and matches the new recommended client.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,120 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromFile endpoint.
+   */
+  public int ingestFromFile(String tableNameWithType, Map<String, String> batchConfigMap, File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromFileUrl(tableNameWithType, batchConfigMap), inputFile);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromURI endpoint.
+   */
+  public int ingestFromUri(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri,
+      File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromUriUrl(tableNameWithType, batchConfigMap, sourceUri), inputFile);
+  }
+
+  /**
+   * Posts a multipart file to an explicit URL.
+   */
+  public int postFile(String url, File inputFile)
+      throws PinotAdminException {
+    HttpEntity reqEntity =
+        MultipartEntityBuilder.create().addPart("file", new FileBody(inputFile.getAbsoluteFile())).build();
+    return execute(url, reqEntity);
+  }
+
+  /**
+   * Posts a plain string body to an explicit URL.
+   */
+  public int postString(String url, String body)
+      throws PinotAdminException {
+    return execute(url, new StringEntity(body));
+  }
+
+  private int execute(String url, HttpEntity entity)
+      throws PinotAdminException {
+    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+      HttpPost httpPost = new HttpPost(url);
+      for (Map.Entry<String, String> header : _headers.entrySet()) {
+        httpPost.setHeader(header.getKey(), header.getValue());
+      }
+      httpPost.setEntity(entity);
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        return response.getCode();
+      }
+    } catch (IOException e) {
+      throw new PinotAdminException("Failed to execute file ingest request to " + url, e);
+    }

Review Comment:
   PinotFileIngestClient uses a standalone Apache HttpClient (HttpClients.createDefault()) and ignores any SSLContext configured on PinotAdminTransport/PinotAdminClient. This will break ingest/upload calls against HTTPS controllers that require custom trust material or skip-cert-validation. Consider building the HttpClient with the transport's SSLContext (when present) so file ingest behavior matches the rest of the admin client.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTenantCommand.java:
##########
@@ -156,15 +128,15 @@ public boolean execute()
     }
 
     Tenant tenant = new Tenant(_role, _name, _instanceCount, _offlineInstanceCount, _realtimeInstanceCount);
-    String res = AbstractBaseAdminCommand
-        .sendRequest("POST", ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTenantCreate(),
-            tenant.toJsonString(), AuthProviderUtils.makeAuthHeaders(
-                AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user,
-                _password)));
-
-    LOGGER.info(res);
-    System.out.print(res);
-    return true;
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      String res = adminClient.getTenantClient().createTenant(tenant.toJsonString());
+      LOGGER.info(res);
+      System.out.print(res);
+      return true;

Review Comment:
   This command prints the controller response to stdout via System.out.print(). Per project guidelines, prefer SLF4J logging (or returning the response to the caller) and avoid writing to stdout from commands/library code.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PeerDownloadLLCRealtimeClusterIntegrationTest.java:
##########
@@ -82,9 +82,9 @@ public class PeerDownloadLLCRealtimeClusterIntegrationTest extends BaseRealtimeC
   @Override
   public void setUp()
       throws Exception {
-    System.out.println(String.format(
-        "Using random seed: %s, isDirectAlloc: %s, isConsumerDirConfigured: %s, enableLeadControllerResource: %s",
-        RANDOM_SEED, _isDirectAlloc, _isConsumerDirConfigured, _enableLeadControllerResource));
+    System.out.printf(
+        "Using random seed: %s, isDirectAlloc: %s, isConsumerDirConfigured: %s, enableLeadControllerResource: %s%n",
+        RANDOM_SEED, _isDirectAlloc, _isConsumerDirConfigured, _enableLeadControllerResource);
 

Review Comment:
   This test uses System.out.printf() for logging. Prefer using the existing SLF4J logger (LOGGER) so output is consistently captured/filtered by the test logging configuration.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -150,7 +192,7 @@ public String createSchema(String schemaConfig, boolean force)
    */
   public String createSchema(String schemaConfig)
       throws PinotAdminException {
-    return createSchema(schemaConfig, false);
+    return createSchema(schemaConfig, true, false);
   }

Review Comment:
   PinotSchemaRestletResource defaults schema creation's `override` query param to true, and the sync createSchema() methods now always send `override`. However createSchemaAsync() still only sends `force`, which makes async behavior diverge from sync behavior. Align the async method with the sync API (add `override`, or provide an async overload that accepts it) to avoid surprising differences.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041148273


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -1028,9 +1030,9 @@ private void performForceCommitSegmentMovingTest(RebalanceConfig rebalanceConfig
 
     // Check if segments were committed (only if there were consuming segments to move)
     if (originalConsumingSegmentsToMove != null && !originalConsumingSegmentsToMove.isEmpty()) {
-      response = sendGetRequest(getControllerRequestURLBuilder().forTableConsumingSegmentsInfo(getTableName()));
       ConsumingSegmentInfoReader.ConsumingSegmentsInfoMap consumingSegmentInfoResponse =
-          JsonUtils.stringToObject(response, ConsumingSegmentInfoReader.ConsumingSegmentsInfoMap.class);
+          getOrCreateAdminClient().getTableClient().getConsumingSegmentsInfo(getTableName(),

Review Comment:
   getConsumingSegmentsInfo() should return ConsumingSegmentsInfoMap class directly 



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038927314


##########
pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManagerStatelessTest.java:
##########
@@ -571,28 +568,19 @@ private void validateJob(String taskType, String cronExpression, boolean skipLat
 
   private void addTableConfig(TableConfig tableConfig, String validationTypesToSkip)
       throws IOException {
-    String createTableUriStr =
-        String.format(_controllerRequestURLBuilder.forTableCreate() + "?validationTypesToSkip=%s",
-            validationTypesToSkip);
     try {
-      HttpClient.wrapAndThrowHttpException(
-          _httpClient.sendJsonPostRequest(new URI(createTableUriStr), tableConfig.toJsonString(),
-              Collections.emptyMap()));
-    } catch (HttpErrorStatusException | URISyntaxException e) {
+      getOrCreateAdminClient().getTableClient().createTable(tableConfig.toJsonString(), validationTypesToSkip);
+    } catch (PinotAdminException e) {
       throw new IOException(e);
     }
   }
 
   private void updateTableConfig(TableConfig tableConfig, String validationTypesToSkip)

Review Comment:
   I think the caller for this  method can directly use:   `getOrCreateAdminClient().getTableClient()
             .updateTableConfig(tableConfig.getTableName(), tableConfig.toJsonString(), validationTypesToSkip);`
   
   Apply same for other callers like addTableConfig.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038927314


##########
pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManagerStatelessTest.java:
##########
@@ -571,28 +568,19 @@ private void validateJob(String taskType, String cronExpression, boolean skipLat
 
   private void addTableConfig(TableConfig tableConfig, String validationTypesToSkip)
       throws IOException {
-    String createTableUriStr =
-        String.format(_controllerRequestURLBuilder.forTableCreate() + "?validationTypesToSkip=%s",
-            validationTypesToSkip);
     try {
-      HttpClient.wrapAndThrowHttpException(
-          _httpClient.sendJsonPostRequest(new URI(createTableUriStr), tableConfig.toJsonString(),
-              Collections.emptyMap()));
-    } catch (HttpErrorStatusException | URISyntaxException e) {
+      getOrCreateAdminClient().getTableClient().createTable(tableConfig.toJsonString(), validationTypesToSkip);
+    } catch (PinotAdminException e) {
       throw new IOException(e);
     }
   }
 
   private void updateTableConfig(TableConfig tableConfig, String validationTypesToSkip)

Review Comment:
   I think the caller for this  method can directly use:   `getOrCreateAdminClient().getTableClient()
             .updateTableConfig(tableConfig.getTableName(), tableConfig.toJsonString(), validationTypesToSkip);`
   
   Apply same for other callers .



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038785228


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotClusterAdminClient.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for cluster-level administration operations.
+ */
+public class PinotClusterAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final Map<String, String> _headers;
+
+  public PinotClusterAdminClient(PinotAdminTransport transport, String controllerAddress,
+      Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+
+  public String updateClusterConfig(String configJson)
+      throws PinotAdminException {
+    JsonNode response = _transport.executePost(_controllerAddress, "/cluster/configs", configJson, null, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets all cluster configurations.
+   */
+  public String getClusterConfigs()
+      throws PinotAdminException {
+    JsonNode response = _transport.executeGet(_controllerAddress, "/cluster/configs", null, _headers);
+    return response.toString();
+  }
+
+  public String deleteClusterConfig(String configName)
+      throws PinotAdminException {
+    JsonNode response = _transport.executeDelete(_controllerAddress, "/cluster/configs/" + configName, null,
+        _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task cluster-wide.
+   */
+  public String runPeriodicTask(String taskName)
+      throws PinotAdminException {
+    Map<String, String> queryParams = Map.of("taskname", taskName);
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task for a specific table and type.
+   */
+  public String runPeriodicTask(String taskName, @Nullable String tableName, @Nullable String tableType)
+      throws PinotAdminException {
+    Map<String, String> queryParams = new java.util.HashMap<>();
+    queryParams.put("taskname", taskName);
+    if (tableName != null) {
+      queryParams.put("tableName", tableName);
+    }
+    if (tableType != null) {
+      queryParams.put("type", tableType);
+    }
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets table rebalance job status by job id.
+   */
+  public String getRebalanceStatus(String jobId)
+      throws PinotAdminException {
+    JsonNode response = _transport.executeGet(_controllerAddress, "/rebalanceStatus/" + jobId, null, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Cancels a query by client id.
+   */
+  public String cancelQueryByClientId(String clientQueryId)

Review Comment:
   this should be moved to a PinotQueryAdminClient



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038849754


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,12 +77,11 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
-    TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
-    srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
-    execEnv.execute();
+    try (PinotAdminClient client = new PinotAdminClient("localhost:9000")) {
+      Schema schema = client.getSchemaClient().getSchema("starbucksStores");
+      TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");

Review Comment:
   remove method PinotConnectionUtils.getTableConfig, just use PinotAdminClient.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039123618


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromFile endpoint.
+   */
+  public int ingestFromFile(String tableNameWithType, Map<String, String> batchConfigMap, File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromFileUrl(tableNameWithType, batchConfigMap), inputFile);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromURI endpoint.
+   */
+  public int ingestFromUri(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri,
+      File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromUriUrl(tableNameWithType, batchConfigMap, sourceUri), inputFile);
+  }
+
+  /**
+   * Posts a multipart file to an explicit URL.
+   */
+  public int postFile(String url, File inputFile)
+      throws PinotAdminException {
+    HttpEntity reqEntity =
+        MultipartEntityBuilder.create().addPart("file", new FileBody(inputFile.getAbsoluteFile())).build();
+    return execute(url, reqEntity);
+  }
+
+  /**
+   * Posts a plain string body to an explicit URL.
+   */
+  public int postString(String url, String body)
+      throws PinotAdminException {
+    return execute(url, new StringEntity(body));
+  }
+
+  private int execute(String url, HttpEntity entity)
+      throws PinotAdminException {
+    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+      HttpPost httpPost = new HttpPost(url);
+      for (Map.Entry<String, String> header : _headers.entrySet()) {
+        httpPost.setHeader(header.getKey(), header.getValue());
+      }
+      httpPost.setEntity(entity);
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        return response.getCode();
+      }
+    } catch (IOException e) {
+      throw new PinotAdminException("Failed to execute file ingest request to " + url, e);
+    }

Review Comment:
   PinotFileIngestClient executes uploads using HttpClients.createDefault() and doesn't apply the SSLContext configured on PinotAdminTransport/PinotAdminClient. This means ingest/upload calls will fail against HTTPS controllers that require a custom truststore or mutual TLS (even though the rest of the admin client supports SSLContext). Consider building the Apache HttpClient with the transport's SSLContext (when present) and/or reusing a single client instance to avoid recreating connections per request.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -911,25 +909,33 @@ private MetricFieldSpec constructNewMetric(FieldSpec.DataType dataType) {
     return new MetricFieldSpec(column, dataType);
   }
 
+  protected RebalanceResult triggerTableRebalance(RebalanceConfig rebalanceConfig, TableType tableType)
+      throws IOException, PinotAdminException {
+    Map<String, String> queryParams = new HashMap<>();
+    queryParams.put("type", tableType.toString());
+    String[] params = rebalanceConfig.toQueryString().split("&");
+    for (String param : params) {
+      String[] kv = param.split("=", 2);
+      if (kv.length == 2) {
+        queryParams.put(kv[0], kv[1]);
+      }
+    }
+    return getOrCreateAdminClient().getRebalanceClient()
+        .rebalanceTable(getTableName(), queryParams, RebalanceResult.class);
+  }
+
+  @Deprecated
   protected String getTableRebalanceUrl(RebalanceConfig rebalanceConfig, TableType tableType) {
-    return StringUtil.join("/", getControllerRequestURLBuilder().getBaseUrl(), "tables", getTableName(), "rebalance")
-        + "?type=" + tableType.toString() + "&" + rebalanceConfig.toQueryString();
+    return controllerUrl(StringUtil.join("/", "tables", getTableName(), "rebalance"))
+        + "?type=" + tableType + "&" + rebalanceConfig.toQueryString();
   }
 
   protected void waitForRebalanceToComplete(String rebalanceJobId, long timeoutMs) {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forTableRebalanceStatus(rebalanceJobId);
-        SimpleHttpResponse httpResponse =
-            HttpClient.wrapAndThrowHttpException(getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null));
-        ServerRebalanceJobStatusResponse rebalanceStatus =
-            JsonUtils.stringToObject(httpResponse.getResponse(), ServerRebalanceJobStatusResponse.class);
+        ServerRebalanceJobStatusResponse rebalanceStatus = getOrCreateAdminClient().getRebalanceClient()
+            .getRebalanceStatus(rebalanceJobId, ServerRebalanceJobStatusResponse.class);
         return rebalanceStatus.getTableRebalanceProgressStats().getStatus() == RebalanceResult.Status.DONE;
-      } catch (HttpErrorStatusException e) {
-        if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
-          Assert.fail("Caught unexpected HTTP error while waiting for rebalance to complete: " + e.getMessage(), e);
-        }
-        return null;
       } catch (Exception e) {
         Assert.fail("Caught exception while waiting for rebalance to complete", e);
         return null;

Review Comment:
   waitForRebalanceToComplete() now fails the test on any exception while polling rebalance status. Previously this polling logic explicitly tolerated transient 404/NOT_FOUND responses (job metadata not yet persisted), returning null to keep waiting. With the admin client, a 404 will surface as PinotAdminNotFoundException and will now immediately Assert.fail(), which can reintroduce test flakiness. Consider catching PinotAdminNotFoundException (or checking for a 404 root cause) and returning null/false so the wait loop continues until the job is visible or the timeout expires.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }

Review Comment:
   buildIngestFromFileUrl()/buildIngestFromUriUrl() manually assemble a JSON string for batchConfigMapStr without escaping keys/values. This will produce invalid JSON if any key/value contains quotes, backslashes, or other characters needing escaping. Prefer using PinotAdminTransport's ObjectMapper / JsonUtils.objectToString(batchConfigMap) to generate JSON, and then URL-encode the result.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3040981762


##########
pinot-connectors/pinot-flink-connector/README.md:
##########
@@ -36,9 +36,9 @@ ControllerRequestClient client = new ControllerRequestClient(
 ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
 
 // fetch Pinot schema
-Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+Schema schema = client.getSchemaClient().getSchemaObject("starbucksStores");
 // fetch Pinot table config
-TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
+TableConfig tableConfig = client.getTableClient().getTableConfigObject("starbucksStores", "OFFLINE");

Review Comment:
   Acknowledged - will update the README snippet in a follow-up.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -150,7 +192,7 @@ public String createSchema(String schemaConfig, boolean force)
    */
   public String createSchema(String schemaConfig)
       throws PinotAdminException {
-    return createSchema(schemaConfig, false);
+    return createSchema(schemaConfig, true, false);
   }

Review Comment:
   Acknowledged - the createSchema override default is consistent with the controller endpoint behavior.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTenantCommand.java:
##########
@@ -156,15 +128,15 @@ public boolean execute()
     }
 
     Tenant tenant = new Tenant(_role, _name, _instanceCount, _offlineInstanceCount, _realtimeInstanceCount);
-    String res = AbstractBaseAdminCommand
-        .sendRequest("POST", ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTenantCreate(),
-            tenant.toJsonString(), AuthProviderUtils.makeAuthHeaders(
-                AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user,
-                _password)));
-
-    LOGGER.info(res);
-    System.out.print(res);
-    return true;
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      String res = adminClient.getTenantClient().createTenant(tenant.toJsonString());
+      LOGGER.info(res);
+      System.out.print(res);
+      return true;

Review Comment:
   Acknowledged - System.out usage in CLI commands is intentional for user-facing output.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PeerDownloadLLCRealtimeClusterIntegrationTest.java:
##########
@@ -82,9 +82,9 @@ public class PeerDownloadLLCRealtimeClusterIntegrationTest extends BaseRealtimeC
   @Override
   public void setUp()
       throws Exception {
-    System.out.println(String.format(
-        "Using random seed: %s, isDirectAlloc: %s, isConsumerDirConfigured: %s, enableLeadControllerResource: %s",
-        RANDOM_SEED, _isDirectAlloc, _isConsumerDirConfigured, _enableLeadControllerResource));
+    System.out.printf(
+        "Using random seed: %s, isDirectAlloc: %s, isConsumerDirConfigured: %s, enableLeadControllerResource: %s%n",
+        RANDOM_SEED, _isDirectAlloc, _isConsumerDirConfigured, _enableLeadControllerResource);
 

Review Comment:
   Acknowledged - will address in a follow-up.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,120 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromFile endpoint.
+   */
+  public int ingestFromFile(String tableNameWithType, Map<String, String> batchConfigMap, File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromFileUrl(tableNameWithType, batchConfigMap), inputFile);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromURI endpoint.
+   */
+  public int ingestFromUri(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri,
+      File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromUriUrl(tableNameWithType, batchConfigMap, sourceUri), inputFile);
+  }
+
+  /**
+   * Posts a multipart file to an explicit URL.
+   */
+  public int postFile(String url, File inputFile)
+      throws PinotAdminException {
+    HttpEntity reqEntity =
+        MultipartEntityBuilder.create().addPart("file", new FileBody(inputFile.getAbsoluteFile())).build();
+    return execute(url, reqEntity);
+  }
+
+  /**
+   * Posts a plain string body to an explicit URL.
+   */
+  public int postString(String url, String body)
+      throws PinotAdminException {
+    return execute(url, new StringEntity(body));
+  }
+
+  private int execute(String url, HttpEntity entity)
+      throws PinotAdminException {
+    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+      HttpPost httpPost = new HttpPost(url);
+      for (Map.Entry<String, String> header : _headers.entrySet()) {
+        httpPost.setHeader(header.getKey(), header.getValue());
+      }
+      httpPost.setEntity(entity);
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        return response.getCode();
+      }
+    } catch (IOException e) {
+      throw new PinotAdminException("Failed to execute file ingest request to " + url, e);
+    }

Review Comment:
   Fixed in earlier commit - PinotFileIngestClient now applies SSLContext from transport via buildHttpClient().



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039231857


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,10 +77,8 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+    PinotAdminClient client = new PinotAdminClient("localhost:9000");
+    Schema schema = client.getSchemaClient().getSchema("starbucksStores");

Review Comment:
   Resolved - FlinkQuickStart now uses getSchemaObject() which returns a typed Schema.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -69,17 +71,30 @@ public String getSchemasInfo()
   }
 
   /**
-   * Gets a specific schema by name.
+   * Gets a specific schema string by name.
    *
    * @param schemaName Name of the schema
    * @return Schema configuration as JSON string
    * @throws PinotAdminException If the request fails
    */
-  public String getSchema(String schemaName)
+  public String getSchemaString(String schemaName)

Review Comment:
   Resolved - getSchemaString() has been removed. getSchema() returns JSON string, getSchemaObject() returns typed Schema.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/http/PinotConnectionUtils.java:
##########
@@ -58,7 +64,7 @@ public static TableConfig getTableConfig(ControllerRequestClient client, String
 
     Map<String, String> newBatchConfigMap = new HashMap<>();
     // append the batch config of controller URI
-    String controllerBaseUrl = client.getControllerRequestURLBuilder().getBaseUrl();
+    String controllerBaseUrl = "http://" + client.getControllerAddress();

Review Comment:
   Resolved - PinotConnectionUtils has been removed. The admin client uses getControllerBaseUrl() which respects the transport scheme.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,10 +77,8 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+    PinotAdminClient client = new PinotAdminClient("localhost:9000");
+    Schema schema = client.getSchemaClient().getSchema("starbucksStores");
     TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
     srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
     execEnv.execute();

Review Comment:
   Resolved - FlinkQuickStart now uses try-with-resources to properly close PinotAdminClient.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotLogicalTableAdminClient.java:
##########
@@ -0,0 +1,72 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Client for logical table administration operations.
+ */
+public class PinotLogicalTableAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final java.util.Map<String, String> _headers;
+
+  public PinotLogicalTableAdminClient(PinotAdminTransport transport, String controllerAddress,
+      java.util.Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+
+  public String createLogicalTable(String logicalTableConfigJson)
+      throws PinotAdminException {
+    JsonNode response = _transport.executePost(_controllerAddress, "/logicalTables", logicalTableConfigJson, null,
+        _headers);
+    System.out.println("createLogicalTable response: " + response.toString());

Review Comment:
   Resolved - System.out.println removed from PinotLogicalTableAdminClient.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038847715


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/http/PinotConnectionUtils.java:
##########
@@ -38,18 +38,23 @@ public final class PinotConnectionUtils {
   private PinotConnectionUtils() {
   }
 
-  public static Schema getSchema(ControllerRequestClient client, String tableName) {
+  public static Schema getSchema(PinotAdminClient client, String tableName) {
     try {
-      return client.getSchema(tableName);
+      return client.getSchemaClient().getSchema(tableName);
     } catch (Exception e) {
       throw new RuntimeException(String.format("Failed to get table schema %s from Pinot controller", tableName), e);
     }
   }
 
-  public static TableConfig getTableConfig(ControllerRequestClient client, String tableName, String tableType) {
+  public static TableConfig getTableConfig(PinotAdminClient client, String tableName, String tableType) {
     TableConfig tableConfig;
     try {
-      tableConfig = client.getTableConfig(tableName, TableType.valueOf(tableType));
+      String configJson = client.getTableClient().getTableConfig(tableName, tableType);

Review Comment:
   PinotAdminClient.getTableClient().getTableConfig() should return `TableConfig` class 



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038887608


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotIngestionRestletResourceStatelessTest.java:
##########
@@ -100,13 +102,14 @@ public void testIngestEndpoint()
     Map<String, String> batchConfigMap = new HashMap<>();
     batchConfigMap.put(BatchConfigProperties.INPUT_FORMAT, "csv");
     batchConfigMap.put(String.format("%s.delimiter", BatchConfigProperties.RECORD_READER_PROP_PREFIX), "|");
-    sendHttpPost(_controllerRequestURLBuilder.forIngestFromFile(TABLE_NAME_WITH_TYPE, batchConfigMap));
+    sendHttpPost(adminClient.getTableClient().buildIngestFromFileUrl(TABLE_NAME_WITH_TYPE, batchConfigMap));

Review Comment:
   Should create a `PinotFileIngestClient` to replace sendHttpPost



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038970111


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PartialUpsertTableRebalanceIntegrationTest.java:
##########
@@ -447,16 +435,10 @@ protected void waitForReloadToComplete(String reloadJobId, long timeoutMs)
       throws Exception {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forSegmentReloadStatus(reloadJobId);
-        try {
-          SimpleHttpResponse httpResponse =
-              HttpClient.wrapAndThrowHttpException(_httpClient.sendGetRequest(new URL(requestUrl).toURI(), null));
-          PinotTableReloadStatusResponse segmentReloadStatusValue =
-              JsonUtils.stringToObject(httpResponse.getResponse(), PinotTableReloadStatusResponse.class);
-          return segmentReloadStatusValue.getSuccessCount() == segmentReloadStatusValue.getTotalSegmentCount();
-        } catch (HttpErrorStatusException | URISyntaxException e) {
-          throw new IOException(e);
-        }
+        String response = getOrCreateAdminClient().getSegmentClient().getSegmentReloadStatus(reloadJobId);

Review Comment:
   getSegmentReloadStatus should return PinotTableReloadStatusResponse



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041368338


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/TlsIntegrationTest.java:
##########
@@ -499,8 +536,12 @@ public void testControllerBrokerQueryForward()
   @Test(expectedExceptions = IOException.class)
   public void testUnauthenticatedFailure()
       throws IOException {
-    sendDeleteRequest(
-        _controllerRequestURLBuilder.forTableDelete(TableNameBuilder.REALTIME.tableNameWithType("mytable")));
+    HttpDelete request = new HttpDelete(
+        "https://localhost:" + _externalControllerPort + "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(
+            getTableName()));
+    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
+      client.execute(request);
+    }

Review Comment:
   This unauthenticated TLS test now uses a default Apache HttpClient without the test SSLContext, so the expected IOException is likely coming from TLS handshake/trust failure rather than an authentication/authorization failure. To keep the test asserting the intended behavior, make the request using the configured SSLContext (or PinotAdminClient without auth headers) and assert the controller returns/raises an auth failure (e.g., 401/PinotAdminAuthenticationException).



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotAccessControlUserRestletResourceTest.java:
##########
@@ -91,17 +61,17 @@ public void testUpdateUserConfig()
     String username = "updateTC";
     String userConfigString =
         _userConfigBuilder.setUsername(username).setComponentType(ComponentType.CONTROLLER).build().toJsonString();
-    ControllerTest.sendPostRequest(_createUserUrl, userConfigString);
+    TEST_INSTANCE.getOrCreateAdminClient().getUserClient().createUser(userConfigString);
     // user creation should succeed

Review Comment:
   This test class no longer covers user creation failure scenarios (e.g., rejecting usernames with '.'/spaces, or creating an already-existing user). Since the PR is a client migration, it would be better to preserve those assertions using PinotUserAdminClient (expecting the appropriate exception/status) to avoid losing coverage of controller validation behavior.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Add typed admin client APIs with response classes in pinot-common; migrate tests and connectors to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3048940723


##########
pinot-controller/src/test/java/org/apache/pinot/controller/helix/ControllerInstanceToggleTest.java:
##########
@@ -110,19 +111,24 @@ public void testInstanceToggle()
     }
 
     // Delete table
-    sendDeleteRequest(DEFAULT_INSTANCE.getControllerRequestURLBuilder().forTableDelete(RAW_TABLE_NAME));
+    adminClient.getTableClient().deleteTable(RAW_TABLE_NAME);
     assertEquals(DEFAULT_INSTANCE.getHelixAdmin()
         .getResourceIdealState(DEFAULT_INSTANCE.getHelixClusterName(), CommonConstants.Helix.BROKER_RESOURCE_INSTANCE)
         .getPartitionSet().size(), 0);
   }
 
   private void toggleInstanceState(String instanceName, String state) {
+    PinotAdminClient adminClient;
+    try {
+      adminClient = getOrCreateAdminClient();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
     // It may take time for an instance to toggle the state.
     TestUtils.waitForCondition(aVoid -> {
       try {
-        sendPutRequest(
-            DEFAULT_INSTANCE.getControllerRequestURLBuilder().forInstanceState(instanceName) + "?state=" + state);
-      } catch (IOException ioe) {
+        adminClient.getInstanceClient().setInstanceState(instanceName, state);
+      } catch (Exception ioe) {

Review Comment:
   This helper uses `InstanceAdminClient.setInstanceState(instanceName, state)`, which targets the deprecated POST `/instances/{instanceName}/state` endpoint. Since the controller now has a non-deprecated PUT endpoint that takes `state` as a query param, consider switching the test to call `InstanceAdminClient.updateInstanceState(...)` (or an equivalent non-deprecated client method) to avoid relying on an API that may be removed.



##########
pinot-common/src/main/java/org/apache/pinot/common/restlet/resources/TableView.java:
##########
@@ -0,0 +1,33 @@
+/**
+ * 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.common.restlet.resources;

Review Comment:
   PR description says the relocated response classes live under `org.apache.pinot.common.response`, but the new/relocated classes in this change use `org.apache.pinot.common.restlet.resources` (e.g., this file). Please align the PR description (or package naming) to avoid confusion for downstream users migrating imports.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039202101


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,120 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromFile endpoint.
+   */
+  public int ingestFromFile(String tableNameWithType, Map<String, String> batchConfigMap, File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromFileUrl(tableNameWithType, batchConfigMap), inputFile);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromURI endpoint.
+   */
+  public int ingestFromUri(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri,
+      File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromUriUrl(tableNameWithType, batchConfigMap, sourceUri), inputFile);
+  }
+
+  /**
+   * Posts a multipart file to an explicit URL.
+   */
+  public int postFile(String url, File inputFile)
+      throws PinotAdminException {
+    HttpEntity reqEntity =
+        MultipartEntityBuilder.create().addPart("file", new FileBody(inputFile.getAbsoluteFile())).build();
+    return execute(url, reqEntity);
+  }
+
+  /**
+   * Posts a plain string body to an explicit URL.
+   */
+  public int postString(String url, String body)
+      throws PinotAdminException {
+    return execute(url, new StringEntity(body));
+  }
+
+  private int execute(String url, HttpEntity entity)
+      throws PinotAdminException {
+    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+      HttpPost httpPost = new HttpPost(url);
+      for (Map.Entry<String, String> header : _headers.entrySet()) {
+        httpPost.setHeader(header.getKey(), header.getValue());
+      }
+      httpPost.setEntity(entity);
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        return response.getCode();
+      }

Review Comment:
   `execute()` creates a new `CloseableHttpClient` per request and does not apply the `SSLContext` configured on `PinotAdminTransport` (so HTTPS/self-signed test setups can fail even when the admin client was constructed with a custom SSL context). Consider reusing a single client instance and configuring it with `_transport`’s SSL context + reasonable timeouts.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,12 +76,11 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
-    TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
-    srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
-    execEnv.execute();
+    try (PinotAdminClient client = new PinotAdminClient("localhost:9000")) {
+      Schema schema = client.getSchemaClient().getSchemaObject("starbucksStores");
+      TableConfig tableConfig = client.getTableClient().getTableConfigObject("starbucksStores", "OFFLINE");
+      srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
+      execEnv.execute();

Review Comment:
   `FlinkQuickStart` now hard-codes the controller address as `"localhost:9000"`, while `DEFAULT_CONTROLLER_URL` is still defined as `"http://localhost:9000"`. This makes it harder to switch schemes/hosts and is inconsistent with the README example; consider using `DEFAULT_CONTROLLER_URL` (parsing to host:port + scheme properties) or at least reusing a single constant for the address.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/LaunchBackfillIngestionJobCommand.java:
##########
@@ -102,7 +102,7 @@ public boolean execute()
       Properties transportProperties = getTransportProperties(spec);
       PinotAdminClient adminClient = new PinotAdminClient(controllerAddress, transportProperties, authHeader);
 
-      _pinotSegmentApiClient = adminClient.getSegmentApiClient();
+      _pinotSegmentAdminClient = adminClient.getSegmentClient();
       // 1. Fetch existing segments that need to be backfilled (to be replaced)

Review Comment:
   `PinotAdminClient` is created but never closed. Since it owns an underlying async HTTP transport, this can leak threads/connections across command runs. Wrap the client creation in try-with-resources (or ensure it’s closed in a finally block) and keep the segment client usage within that scope.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,120 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }

Review Comment:
   `batchConfigMapStr` is manually assembled with string concatenation, which won’t correctly escape keys/values containing quotes, backslashes, or other JSON-sensitive characters. Build this JSON via the shared ObjectMapper/JsonUtils (e.g., serialize `batchConfigMap`) and URL-encode `tableNameWithType` as well (it’s currently appended unencoded).



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039175363


##########
pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManagerStatelessTest.java:
##########
@@ -571,28 +568,19 @@ private void validateJob(String taskType, String cronExpression, boolean skipLat
 
   private void addTableConfig(TableConfig tableConfig, String validationTypesToSkip)
       throws IOException {
-    String createTableUriStr =
-        String.format(_controllerRequestURLBuilder.forTableCreate() + "?validationTypesToSkip=%s",
-            validationTypesToSkip);
     try {
-      HttpClient.wrapAndThrowHttpException(
-          _httpClient.sendJsonPostRequest(new URI(createTableUriStr), tableConfig.toJsonString(),
-              Collections.emptyMap()));
-    } catch (HttpErrorStatusException | URISyntaxException e) {
+      getOrCreateAdminClient().getTableClient().createTable(tableConfig.toJsonString(), validationTypesToSkip);
+    } catch (PinotAdminException e) {
       throw new IOException(e);
     }
   }
 
   private void updateTableConfig(TableConfig tableConfig, String validationTypesToSkip)

Review Comment:
   Done - callers now use admin client directly.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/UrlAuthRealtimeIntegrationTest.java:
##########
@@ -150,7 +149,7 @@ protected Map<String, String> getPinotClientTransportHeaders() {
   public void testUnauthenticatedFailure()
       throws IOException {
     sendDeleteRequest(

Review Comment:
   Done - sendDeleteRequest calls migrated to admin client delete methods.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/TableRebalancePauselessIntegrationTest.java:
##########
@@ -186,9 +186,9 @@ public void testForceCommit(TableConfig tableConfig)
       // notice that this could get an HTTP 409 CONFLICT, when the test failed due to the timeout waiting on the table
       // to converge, and try to rebalance again here. So we need to cancel the original job first.
       sendDeleteRequest(

Review Comment:
   Done - PinotRebalanceAdminClient has rebalanceTable and cancelRebalance APIs.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PartialUpsertTableRebalanceIntegrationTest.java:
##########
@@ -447,16 +435,10 @@ protected void waitForReloadToComplete(String reloadJobId, long timeoutMs)
       throws Exception {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forSegmentReloadStatus(reloadJobId);
-        try {
-          SimpleHttpResponse httpResponse =
-              HttpClient.wrapAndThrowHttpException(_httpClient.sendGetRequest(new URL(requestUrl).toURI(), null));
-          PinotTableReloadStatusResponse segmentReloadStatusValue =
-              JsonUtils.stringToObject(httpResponse.getResponse(), PinotTableReloadStatusResponse.class);
-          return segmentReloadStatusValue.getSuccessCount() == segmentReloadStatusValue.getTotalSegmentCount();
-        } catch (HttpErrorStatusException | URISyntaxException e) {
-          throw new IOException(e);
-        }
+        String response = getOrCreateAdminClient().getSegmentClient().getSegmentReloadStatus(reloadJobId);

Review Comment:
   Done - getSegmentReloadStatus has typed overload returning PinotTableReloadStatusResponse.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/KafkaConsumingSegmentToBeMovedSummaryIntegrationTest.java:
##########
@@ -143,8 +143,8 @@ public void testConsumingSegmentSummary()
         .reduce(0L, (a, b) -> a + b.getTotalOffsetsToCatchUpAcrossAllConsumingSegments(), Long::sum), 57801);
 
     // set includeConsuming to false
-    response = sendPostRequest(
-        getControllerRequestURLBuilder().forTableRebalance(getTableName(), "REALTIME", true, false, false, false, -1));
+    response = getOrCreateAdminClient().getTableClient()

Review Comment:
   Done - rebalanceTable has typed overload returning RebalanceResult.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r2505959570


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,10 +77,8 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+    PinotAdminClient client = new PinotAdminClient("localhost:9000");
+    Schema schema = client.getSchemaClient().getSchema("starbucksStores");

Review Comment:
   The `getSchema()` method now returns a Schema object instead of a String, but this line treats it as if it returns a String. This will cause a compilation error since the Schema type from `getSchemaClient().getSchema()` is being used directly without conversion.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -69,17 +71,30 @@ public String getSchemasInfo()
   }
 
   /**
-   * Gets a specific schema by name.
+   * Gets a specific schema string by name.
    *
    * @param schemaName Name of the schema
    * @return Schema configuration as JSON string
    * @throws PinotAdminException If the request fails
    */
-  public String getSchema(String schemaName)
+  public String getSchemaString(String schemaName)

Review Comment:
   The method `getSchemaString()` is introduced but lacks a corresponding update to the overloaded `getSchema()` method's documentation. Since both methods exist with different return types, their relationship and use cases should be clarified in the class-level documentation or method comments.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/http/PinotConnectionUtils.java:
##########
@@ -58,7 +64,7 @@ public static TableConfig getTableConfig(ControllerRequestClient client, String
 
     Map<String, String> newBatchConfigMap = new HashMap<>();
     // append the batch config of controller URI
-    String controllerBaseUrl = client.getControllerRequestURLBuilder().getBaseUrl();
+    String controllerBaseUrl = "http://" + client.getControllerAddress();

Review Comment:
   Hard-coding the scheme as 'http://' ignores the transport's actual scheme configuration. This will fail when HTTPS is required. Use `client.getControllerBaseUrl()` instead, which properly incorporates the scheme from the transport.
   ```suggestion
       String controllerBaseUrl = client.getControllerBaseUrl();
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038888258


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotFileUploadTest.java:
##########
@@ -58,8 +58,9 @@ public void setUp()
   @Test
   public void testUploadBogusData()
       throws Exception {
+    String uploadUrl = TEST_INSTANCE.getAdminClient().getSegmentUploadUrl();
     try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
-      HttpPost httpPost = new HttpPost(TEST_INSTANCE.getControllerRequestURLBuilder().forDataFileUpload());
+      HttpPost httpPost = new HttpPost(uploadUrl);

Review Comment:
   Should create a `PinotFileIngestClient` to replace sendHttpPost



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039173134


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotClusterAdminClient.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for cluster-level administration operations.
+ */
+public class PinotClusterAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final Map<String, String> _headers;
+
+  public PinotClusterAdminClient(PinotAdminTransport transport, String controllerAddress,
+      Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+
+  public String updateClusterConfig(String configJson)
+      throws PinotAdminException {
+    JsonNode response = _transport.executePost(_controllerAddress, "/cluster/configs", configJson, null, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets all cluster configurations.
+   */
+  public String getClusterConfigs()
+      throws PinotAdminException {
+    JsonNode response = _transport.executeGet(_controllerAddress, "/cluster/configs", null, _headers);
+    return response.toString();
+  }
+
+  public String deleteClusterConfig(String configName)
+      throws PinotAdminException {
+    JsonNode response = _transport.executeDelete(_controllerAddress, "/cluster/configs/" + configName, null,
+        _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task cluster-wide.
+   */
+  public String runPeriodicTask(String taskName)
+      throws PinotAdminException {
+    Map<String, String> queryParams = Map.of("taskname", taskName);
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task for a specific table and type.
+   */
+  public String runPeriodicTask(String taskName, @Nullable String tableName, @Nullable String tableType)
+      throws PinotAdminException {
+    Map<String, String> queryParams = new java.util.HashMap<>();
+    queryParams.put("taskname", taskName);
+    if (tableName != null) {
+      queryParams.put("tableName", tableName);
+    }
+    if (tableType != null) {
+      queryParams.put("type", tableType);
+    }
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets table rebalance job status by job id.
+   */
+  public String getRebalanceStatus(String jobId)

Review Comment:
   Done - PinotRebalanceAdminClient already exists as a separate class with rebalance methods.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotClusterAdminClient.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for cluster-level administration operations.
+ */
+public class PinotClusterAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final Map<String, String> _headers;
+
+  public PinotClusterAdminClient(PinotAdminTransport transport, String controllerAddress,
+      Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+
+  public String updateClusterConfig(String configJson)
+      throws PinotAdminException {
+    JsonNode response = _transport.executePost(_controllerAddress, "/cluster/configs", configJson, null, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets all cluster configurations.
+   */
+  public String getClusterConfigs()
+      throws PinotAdminException {
+    JsonNode response = _transport.executeGet(_controllerAddress, "/cluster/configs", null, _headers);
+    return response.toString();
+  }
+
+  public String deleteClusterConfig(String configName)
+      throws PinotAdminException {
+    JsonNode response = _transport.executeDelete(_controllerAddress, "/cluster/configs/" + configName, null,
+        _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task cluster-wide.
+   */
+  public String runPeriodicTask(String taskName)
+      throws PinotAdminException {
+    Map<String, String> queryParams = Map.of("taskname", taskName);
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task for a specific table and type.
+   */
+  public String runPeriodicTask(String taskName, @Nullable String tableName, @Nullable String tableType)
+      throws PinotAdminException {
+    Map<String, String> queryParams = new java.util.HashMap<>();
+    queryParams.put("taskname", taskName);
+    if (tableName != null) {
+      queryParams.put("tableName", tableName);
+    }
+    if (tableType != null) {
+      queryParams.put("type", tableType);
+    }
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets table rebalance job status by job id.
+   */
+  public String getRebalanceStatus(String jobId)
+      throws PinotAdminException {
+    JsonNode response = _transport.executeGet(_controllerAddress, "/rebalanceStatus/" + jobId, null, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Cancels a query by client id.
+   */
+  public String cancelQueryByClientId(String clientQueryId)

Review Comment:
   Done - PinotQueryAdminClient already exists as a separate class.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotClusterAdminClient.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for cluster-level administration operations.
+ */
+public class PinotClusterAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final Map<String, String> _headers;
+
+  public PinotClusterAdminClient(PinotAdminTransport transport, String controllerAddress,
+      Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+

Review Comment:
   Done - `updateClusterConfig(String configName, String configValue)` already added.



##########
pinot-connectors/pinot-flink-connector/src/test/java/org/apache/pinot/connector/flink/sink/PinotSinkIntegrationTest.java:
##########
@@ -133,17 +130,20 @@ public void testPinotSinkWrite()
   }
 
   private void verifySegments(int numSegments, int numTotalDocs)
-      throws IOException {
-    JsonNode segments = JsonUtils.stringToJsonNode(sendGetRequest(
-            _controllerRequestURLBuilder.forSegmentListAPI(OFFLINE_TABLE_NAME, TableType.OFFLINE.toString()))).get(0)
-        .get("OFFLINE");
+      throws Exception {
+    List<String> segments = getOrCreateAdminClient().getSegmentClient()

Review Comment:
   Done - segment client already extracted to local variable.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotLogicalTableAdminClient.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for logical table administration operations.
+ */
+public class PinotLogicalTableAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final java.util.Map<String, String> _headers;
+
+  public PinotLogicalTableAdminClient(PinotAdminTransport transport, String controllerAddress,
+      java.util.Map<String, String> headers) {

Review Comment:
   Done - replaced all fully-qualified class names with proper imports across all admin client files.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotTableAdminClient.java:
##########
@@ -369,4 +974,18 @@ public CompletableFuture<String> createTableAsync(String tableConfig, String val
     return _transport.executePostAsync(_controllerAddress, "/tables", tableConfig, queryParams, _headers)
         .thenApply(JsonNode::toString);
   }
+
+  private Map<String, String> mergeHeaders(@Nullable Map<String, String> headers) {

Review Comment:
   Done - all admin client classes now extend AbstractPinotAdminClient which provides shared fields and mergeHeaders.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038783272


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotClusterAdminClient.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for cluster-level administration operations.
+ */
+public class PinotClusterAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final Map<String, String> _headers;
+
+  public PinotClusterAdminClient(PinotAdminTransport transport, String controllerAddress,
+      Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+
+  public String updateClusterConfig(String configJson)
+      throws PinotAdminException {
+    JsonNode response = _transport.executePost(_controllerAddress, "/cluster/configs", configJson, null, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets all cluster configurations.
+   */
+  public String getClusterConfigs()
+      throws PinotAdminException {
+    JsonNode response = _transport.executeGet(_controllerAddress, "/cluster/configs", null, _headers);
+    return response.toString();
+  }
+
+  public String deleteClusterConfig(String configName)
+      throws PinotAdminException {
+    JsonNode response = _transport.executeDelete(_controllerAddress, "/cluster/configs/" + configName, null,
+        _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task cluster-wide.
+   */
+  public String runPeriodicTask(String taskName)
+      throws PinotAdminException {
+    Map<String, String> queryParams = Map.of("taskname", taskName);
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Runs a periodic task for a specific table and type.
+   */
+  public String runPeriodicTask(String taskName, @Nullable String tableName, @Nullable String tableType)
+      throws PinotAdminException {
+    Map<String, String> queryParams = new java.util.HashMap<>();
+    queryParams.put("taskname", taskName);
+    if (tableName != null) {
+      queryParams.put("tableName", tableName);
+    }
+    if (tableType != null) {
+      queryParams.put("type", tableType);
+    }
+    JsonNode response = _transport.executeGet(_controllerAddress, "/periodictask/run", queryParams, _headers);
+    return response.toString();
+  }
+
+  /**
+   * Gets table rebalance job status by job id.
+   */
+  public String getRebalanceStatus(String jobId)

Review Comment:
   Extract this to a PinotRebalanceAdminClient and put other relevant methods into PinotRebalanceAdminClient



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038812853


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotLogicalTableAdminClient.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for logical table administration operations.
+ */
+public class PinotLogicalTableAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final java.util.Map<String, String> _headers;
+
+  public PinotLogicalTableAdminClient(PinotAdminTransport transport, String controllerAddress,
+      java.util.Map<String, String> headers) {

Review Comment:
   import the class don't use fully qualified class name. same for other uages.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039279543


##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/ImportDataCommand.java:
##########
@@ -413,4 +399,24 @@ private String getRecordReaderClass(FileFormat format) {
         throw new IllegalArgumentException("Unsupported file format - " + format);
     }
   }
+
+  private String resolveControllerURI() {
+    if (_controllerUriProvidedExplicitly) {
+      return _controllerURI;
+    }
+    boolean controllerFieldsCustomized =
+        _controllerHost != null || !_controllerPort.equals(DEFAULT_CONTROLLER_PORT)
+            || !_controllerProtocol.equals(CommonConstants.HTTP_PROTOCOL);
+    if (!controllerFieldsCustomized) {
+      return _controllerURI;
+    }
+    try {
+      if (_controllerHost == null) {
+        _controllerHost = NetUtils.getHostAddress();
+      }
+    } catch (SocketException | UnknownHostException e) {
+      throw new IllegalStateException("Failed to determine controller host", e);
+    }
+    return _controllerProtocol + "://" + _controllerHost + ":" + _controllerPort;
+  }

Review Comment:
   Acknowledged - the picocli URI precedence issue is a pre-existing concern outside the scope of this migration PR.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTenantCommand.java:
##########
@@ -110,36 +77,36 @@ public AddTenantCommand setRealtime(int realtime) {
     return this;
   }
 
-  public AddTenantCommand setUser(String user) {
-    _user = user;
-    return this;
-  }
-
-  public AddTenantCommand setPassword(String password) {
-    _password = password;
+  public AddTenantCommand setControllerUrl(String url) {
+    URI uri = URI.create(url);
+    if (uri.getScheme() != null) {
+      _controllerProtocol = uri.getScheme();
+    }
+    if (uri.getHost() != null) {
+      _controllerHost = uri.getHost();
+    }
+    if (uri.getPort() > 0) {
+      _controllerPort = Integer.toString(uri.getPort());
+    }
     return this;

Review Comment:
   Acknowledged - URI parsing for scheme-less inputs is a pre-existing concern. The admin client accepts host:port and manages scheme via transport properties.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -911,25 +909,33 @@ private MetricFieldSpec constructNewMetric(FieldSpec.DataType dataType) {
     return new MetricFieldSpec(column, dataType);
   }
 
+  protected RebalanceResult triggerTableRebalance(RebalanceConfig rebalanceConfig, TableType tableType)
+      throws IOException, PinotAdminException {
+    Map<String, String> queryParams = new HashMap<>();
+    queryParams.put("type", tableType.toString());
+    String[] params = rebalanceConfig.toQueryString().split("&");
+    for (String param : params) {
+      String[] kv = param.split("=", 2);
+      if (kv.length == 2) {
+        queryParams.put(kv[0], kv[1]);
+      }
+    }
+    return getOrCreateAdminClient().getRebalanceClient()
+        .rebalanceTable(getTableName(), queryParams, RebalanceResult.class);
+  }
+
+  @Deprecated
   protected String getTableRebalanceUrl(RebalanceConfig rebalanceConfig, TableType tableType) {
-    return StringUtil.join("/", getControllerRequestURLBuilder().getBaseUrl(), "tables", getTableName(), "rebalance")
-        + "?type=" + tableType.toString() + "&" + rebalanceConfig.toQueryString();
+    return controllerUrl(StringUtil.join("/", "tables", getTableName(), "rebalance"))
+        + "?type=" + tableType + "&" + rebalanceConfig.toQueryString();
   }
 
   protected void waitForRebalanceToComplete(String rebalanceJobId, long timeoutMs) {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forTableRebalanceStatus(rebalanceJobId);
-        SimpleHttpResponse httpResponse =
-            HttpClient.wrapAndThrowHttpException(getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null));
-        ServerRebalanceJobStatusResponse rebalanceStatus =
-            JsonUtils.stringToObject(httpResponse.getResponse(), ServerRebalanceJobStatusResponse.class);
+        ServerRebalanceJobStatusResponse rebalanceStatus = getOrCreateAdminClient().getRebalanceClient()
+            .getRebalanceStatus(rebalanceJobId, ServerRebalanceJobStatusResponse.class);
         return rebalanceStatus.getTableRebalanceProgressStats().getStatus() == RebalanceResult.Status.DONE;
-      } catch (HttpErrorStatusException e) {
-        if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
-          Assert.fail("Caught unexpected HTTP error while waiting for rebalance to complete: " + e.getMessage(), e);
-        }
-        return null;
       } catch (Exception e) {
         Assert.fail("Caught exception while waiting for rebalance to complete", e);
         return null;

Review Comment:
   Acknowledged - the behavior change is intentional since the typed response makes it clearer when rebalance polling encounters errors.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Add typed admin client APIs with response classes in pinot-common; migrate tests and connectors to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 merged PR #17167:
URL: https://github.com/apache/pinot/pull/17167


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3008485204


##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/OperateClusterConfigCommand.java:
##########
@@ -144,36 +87,34 @@ public String run()
     if (StringUtils.isEmpty(_config) && !_operation.equalsIgnoreCase("GET")) {
       throw new UnsupportedOperationException("Empty config: " + _config);
     }
-    String clusterConfigUrl =
-        _controllerProtocol + "://" + _controllerHost + ":" + _controllerPort + "/cluster/configs";
-    List<Header> headers = AuthProviderUtils.makeAuthHeaders(
-        AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user,
-        _password));
-    switch (_operation.toUpperCase()) {
-      case "ADD":
-      case "UPDATE":
-        String[] splits = _config.split("=");
-        if (splits.length != 2) {
-          throw new UnsupportedOperationException(
-              "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
-        }
-        String request = JsonUtils.objectToString(Collections.singletonMap(splits[0], splits[1]));
-        return sendRequest("POST", clusterConfigUrl, request, headers);
-      case "GET":
-        String response = sendRequest("GET", clusterConfigUrl, null, headers);
-        JsonNode jsonNode = JsonUtils.stringToJsonNode(response);
-        Iterator<String> fieldNamesIterator = jsonNode.fieldNames();
-        String results = "";
-        while (fieldNamesIterator.hasNext()) {
-          String key = fieldNamesIterator.next();
-          String value = jsonNode.get(key).textValue();
-          results += String.format("%s=%s\n", key, value);
-        }
-        return results;
-      case "DELETE":
-        return sendRequest("DELETE", String.format("%s/%s", clusterConfigUrl, _config), null, headers);
-      default:
-        throw new UnsupportedOperationException("Unsupported operation: " + _operation);
+    String normalizedOperation = _operation.toUpperCase(Locale.ROOT);
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      switch (normalizedOperation) {
+        case "ADD":
+        case "UPDATE":
+          String[] splits = _config.split("=");
+          if (splits.length != 2) {
+            throw new UnsupportedOperationException(
+                "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
+          }
+          String request = JsonUtils.objectToString(java.util.Collections.singletonMap(splits[0], splits[1]));
+          return adminClient.getClusterClient().updateClusterConfig(request);
+        case "GET":
+          String response = adminClient.getClusterClient().getClusterConfigs();
+          JsonNode jsonNode = JsonUtils.stringToJsonNode(response);
+          StringBuilder results = new StringBuilder();
+          jsonNode.fieldNames().forEachRemaining(key -> {
+            String value = jsonNode.get(key).textValue();
+            results.append(String.format("%s=%s%n", key, value));
+          });
+          return results.toString();
+        case "DELETE":
+          return adminClient.getClusterClient().deleteClusterConfig(_config);
+        default:
+          throw new UnsupportedOperationException("Unsupported operation: " + _operation);
+      }
+    } catch (PinotAdminException e) {
+      throw new RuntimeException("Failed to operate on cluster config", e);

Review Comment:
   Catching `PinotAdminException` and rethrowing a generic `RuntimeException` loses useful context (e.g., HTTP status code / controller error payload) even though `run()` already declares `throws Exception`. Consider either letting `PinotAdminException` propagate, or wrapping it with operation-specific context (include operation/config key) while preserving the original message/status to aid debugging.



##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,10 +77,8 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
+    PinotAdminClient client = new PinotAdminClient("localhost:9000");
+    Schema schema = client.getSchemaClient().getSchema("starbucksStores");
     TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
     srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
     execEnv.execute();

Review Comment:
   `PinotAdminClient` is created in `main()` but never closed. Since it owns an underlying HTTP client/transport, this can leak threads/resources. Wrap it in try-with-resources (or explicitly call `close()`) around the schema/config fetches.
   ```suggestion
       try (PinotAdminClient client = new PinotAdminClient("localhost:9000")) {
         Schema schema = client.getSchemaClient().getSchema("starbucksStores");
         TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
         srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
         execEnv.execute();
       }
   ```



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTenantCommand.java:
##########
@@ -110,36 +77,36 @@ public AddTenantCommand setRealtime(int realtime) {
     return this;
   }
 
-  public AddTenantCommand setUser(String user) {
-    _user = user;
-    return this;
-  }
-
-  public AddTenantCommand setPassword(String password) {
-    _password = password;
+  public AddTenantCommand setControllerUrl(String url) {
+    URI uri = URI.create(url);
+    if (uri.getScheme() != null) {
+      _controllerProtocol = uri.getScheme();
+    }
+    if (uri.getHost() != null) {
+      _controllerHost = uri.getHost();
+    }
+    if (uri.getPort() > 0) {
+      _controllerPort = Integer.toString(uri.getPort());
+    }
     return this;

Review Comment:
   `setControllerUrl(String url)` uses `URI.create(url)` and then reads scheme/host/port. For common inputs like `"localhost:9000"` (no scheme), `URI.create` treats `localhost` as the scheme and leaves host/port unset, which will misconfigure `_controllerProtocol/_controllerHost/_controllerPort`. Consider handling scheme-less inputs (e.g., prefix with `http://`), or preserve the previous behavior of storing a full controller address/URI when no scheme is present.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/OperateClusterConfigCommand.java:
##########
@@ -144,36 +87,34 @@ public String run()
     if (StringUtils.isEmpty(_config) && !_operation.equalsIgnoreCase("GET")) {
       throw new UnsupportedOperationException("Empty config: " + _config);
     }
-    String clusterConfigUrl =
-        _controllerProtocol + "://" + _controllerHost + ":" + _controllerPort + "/cluster/configs";
-    List<Header> headers = AuthProviderUtils.makeAuthHeaders(
-        AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user,
-        _password));
-    switch (_operation.toUpperCase()) {
-      case "ADD":
-      case "UPDATE":
-        String[] splits = _config.split("=");
-        if (splits.length != 2) {
-          throw new UnsupportedOperationException(
-              "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
-        }
-        String request = JsonUtils.objectToString(Collections.singletonMap(splits[0], splits[1]));
-        return sendRequest("POST", clusterConfigUrl, request, headers);
-      case "GET":
-        String response = sendRequest("GET", clusterConfigUrl, null, headers);
-        JsonNode jsonNode = JsonUtils.stringToJsonNode(response);
-        Iterator<String> fieldNamesIterator = jsonNode.fieldNames();
-        String results = "";
-        while (fieldNamesIterator.hasNext()) {
-          String key = fieldNamesIterator.next();
-          String value = jsonNode.get(key).textValue();
-          results += String.format("%s=%s\n", key, value);
-        }
-        return results;
-      case "DELETE":
-        return sendRequest("DELETE", String.format("%s/%s", clusterConfigUrl, _config), null, headers);
-      default:
-        throw new UnsupportedOperationException("Unsupported operation: " + _operation);
+    String normalizedOperation = _operation.toUpperCase(Locale.ROOT);
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      switch (normalizedOperation) {
+        case "ADD":
+        case "UPDATE":
+          String[] splits = _config.split("=");
+          if (splits.length != 2) {
+            throw new UnsupportedOperationException(
+                "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
+          }
+          String request = JsonUtils.objectToString(java.util.Collections.singletonMap(splits[0], splits[1]));
+          return adminClient.getClusterClient().updateClusterConfig(request);

Review Comment:
   Minor: `java.util.Collections.singletonMap(...)` is used via a fully-qualified reference here. Prefer adding an import for `java.util.Collections` (consistent with the rest of the file) to improve readability and keep imports explicit.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotLogicalTableAdminClient.java:
##########
@@ -0,0 +1,72 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Client for logical table administration operations.
+ */
+public class PinotLogicalTableAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final java.util.Map<String, String> _headers;
+
+  public PinotLogicalTableAdminClient(PinotAdminTransport transport, String controllerAddress,
+      java.util.Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+
+  public String createLogicalTable(String logicalTableConfigJson)
+      throws PinotAdminException {
+    JsonNode response = _transport.executePost(_controllerAddress, "/logicalTables", logicalTableConfigJson, null,
+        _headers);
+    System.out.println("createLogicalTable response: " + response.toString());

Review Comment:
   `createLogicalTable()` prints the response via `System.out.println`, which is unexpected for a library client and can pollute caller output. Please remove the stdout write, or replace it with SLF4J logging at an appropriate level (or just return the response and let callers log).
   ```suggestion
   
   ```



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/ImportDataCommand.java:
##########
@@ -413,4 +399,24 @@ private String getRecordReaderClass(FileFormat format) {
         throw new IllegalArgumentException("Unsupported file format - " + format);
     }
   }
+
+  private String resolveControllerURI() {
+    if (_controllerUriProvidedExplicitly) {
+      return _controllerURI;
+    }
+    boolean controllerFieldsCustomized =
+        _controllerHost != null || !_controllerPort.equals(DEFAULT_CONTROLLER_PORT)
+            || !_controllerProtocol.equals(CommonConstants.HTTP_PROTOCOL);
+    if (!controllerFieldsCustomized) {
+      return _controllerURI;
+    }
+    try {
+      if (_controllerHost == null) {
+        _controllerHost = NetUtils.getHostAddress();
+      }
+    } catch (SocketException | UnknownHostException e) {
+      throw new IllegalStateException("Failed to determine controller host", e);
+    }
+    return _controllerProtocol + "://" + _controllerHost + ":" + _controllerPort;
+  }

Review Comment:
   `_controllerUriProvidedExplicitly` is only set in `setControllerURI()`, but picocli will set `_controllerURI` directly when `-controllerURI` is passed on the command line. As a result, `resolveControllerURI()` can incorrectly treat a user-supplied `-controllerURI` as “not explicit” and override it when `-controllerHost/-controllerPort/-controllerProtocol` are also set. Consider detecting explicit CLI usage via picocli parse results/spec, or alternatively fail fast when both `-controllerURI` and any controller host/port/protocol options are provided to avoid ambiguous precedence.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041134745


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/StaleSegmentCheckIntegrationTest.java:
##########
@@ -165,10 +163,9 @@ public void testH3IndexChange()
   }
 
   private Map<String, TableStaleSegmentResponse> getStaleSegmentsResponse()
-      throws IOException {
-    return JsonUtils.stringToObject(sendGetRequest(
-            _controllerRequestURLBuilder.forStaleSegments(
-                TableNameBuilder.OFFLINE.tableNameWithType(getTableName()))),
+      throws Exception {
+    return getOrCreateAdminClient().getSegmentClient().getStaleSegments(

Review Comment:
   getStaleSegments() method  should return `Map<String, TableStaleSegmentResponse>`



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038818600


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotTableAdminClient.java:
##########
@@ -369,4 +974,18 @@ public CompletableFuture<String> createTableAsync(String tableConfig, String val
     return _transport.executePostAsync(_controllerAddress, "/tables", tableConfig, queryParams, _headers)
         .thenApply(JsonNode::toString);
   }
+
+  private Map<String, String> mergeHeaders(@Nullable Map<String, String> headers) {

Review Comment:
   Extract mergeHeaders and other common methods in the client classes to a common interface or abstract class.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on PR #17167:
URL: https://github.com/apache/pinot/pull/17167#issuecomment-4192081158

   @copilot review


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041130836


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/QueryQuotaClusterIntegrationTest.java:
##########
@@ -65,6 +66,7 @@ public class QueryQuotaClusterIntegrationTest extends BaseClusterIntegrationTest
   public void setUp()
       throws Exception {
     TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir);
+    _httpClient = getHttpClient();

Review Comment:
   should remove this _httpClient from this class and its parent class like: BaseClusterIntegrationTest
   
   Move _httpClient usage to admin client



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041200926


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/TenantRebalanceIntegrationTest.java:
##########
@@ -32,9 +32,16 @@
 
 public class TenantRebalanceIntegrationTest extends BaseHybridClusterIntegrationTest {
 
-  private String getRebalanceUrl() {
-    return StringUtil.join("/", getControllerRequestURLBuilder().getBaseUrl(), "tenants", getServerTenant(),
-        "rebalance");
+  private TenantRebalanceResult rebalanceTenant(TenantRebalanceConfig config, @Nullable Map<String, String> queryParams)
+      throws Exception {
+    return getOrCreateAdminClient().getTenantClient()
+        .rebalanceTenantWithConfig(config.getTenantName(), JsonUtils.objectToString(config), queryParams,

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/QueryQuotaClusterIntegrationTest.java:
##########
@@ -65,6 +66,7 @@ public class QueryQuotaClusterIntegrationTest extends BaseClusterIntegrationTest
   public void setUp()
       throws Exception {
     TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir);
+    _httpClient = getHttpClient();

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/StaleSegmentCheckIntegrationTest.java:
##########
@@ -165,10 +163,9 @@ public void testH3IndexChange()
   }
 
   private Map<String, TableStaleSegmentResponse> getStaleSegmentsResponse()
-      throws IOException {
-    return JsonUtils.stringToObject(sendGetRequest(
-            _controllerRequestURLBuilder.forStaleSegments(
-                TableNameBuilder.OFFLINE.tableNameWithType(getTableName()))),
+      throws Exception {
+    return getOrCreateAdminClient().getSegmentClient().getStaleSegments(

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -911,24 +909,35 @@ private MetricFieldSpec constructNewMetric(FieldSpec.DataType dataType) {
     return new MetricFieldSpec(column, dataType);
   }
 
+  protected RebalanceResult triggerTableRebalance(RebalanceConfig rebalanceConfig, TableType tableType)
+      throws IOException, PinotAdminException {
+    Map<String, String> queryParams = new HashMap<>();
+    queryParams.put("type", tableType.toString());
+    String[] params = rebalanceConfig.toQueryString().split("&");
+    for (String param : params) {
+      String[] kv = param.split("=", 2);
+      if (kv.length == 2) {
+        queryParams.put(kv[0], kv[1]);
+      }
+    }
+    return getOrCreateAdminClient().getRebalanceClient()

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -940,16 +949,10 @@ protected void waitForRebalanceToComplete(String rebalanceJobId, long timeoutMs)
   protected void waitForTableEVISConverge(String tableName, long timeoutMs) {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forIdealState(tableName);
-        SimpleHttpResponse httpResponse =
-            HttpClient.wrapAndThrowHttpException(getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null));
         TableViews.TableView idealState =
-            JsonUtils.stringToObject(httpResponse.getResponse(), TableViews.TableView.class);
-
-        requestUrl = getControllerRequestURLBuilder().forExternalView(tableName);
-        httpResponse = getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null);
+            getOrCreateAdminClient().getTableClient().getIdealState(tableName, TableViews.TableView.class);

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -940,16 +949,10 @@ protected void waitForRebalanceToComplete(String rebalanceJobId, long timeoutMs)
   protected void waitForTableEVISConverge(String tableName, long timeoutMs) {
     TestUtils.waitForCondition(aVoid -> {
       try {
-        String requestUrl = getControllerRequestURLBuilder().forIdealState(tableName);
-        SimpleHttpResponse httpResponse =
-            HttpClient.wrapAndThrowHttpException(getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null));
         TableViews.TableView idealState =
-            JsonUtils.stringToObject(httpResponse.getResponse(), TableViews.TableView.class);
-
-        requestUrl = getControllerRequestURLBuilder().forExternalView(tableName);
-        httpResponse = getHttpClient().sendGetRequest(new URL(requestUrl).toURI(), null);
+            getOrCreateAdminClient().getTableClient().getIdealState(tableName, TableViews.TableView.class);
         TableViews.TableView externalView =
-            JsonUtils.stringToObject(httpResponse.getResponse(), TableViews.TableView.class);
+            getOrCreateAdminClient().getTableClient().getExternalView(tableName, TableViews.TableView.class);

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTestSet.java:
##########
@@ -1028,9 +1030,9 @@ private void performForceCommitSegmentMovingTest(RebalanceConfig rebalanceConfig
 
     // Check if segments were committed (only if there were consuming segments to move)
     if (originalConsumingSegmentsToMove != null && !originalConsumingSegmentsToMove.isEmpty()) {
-      response = sendGetRequest(getControllerRequestURLBuilder().forTableConsumingSegmentsInfo(getTableName()));
       ConsumingSegmentInfoReader.ConsumingSegmentsInfoMap consumingSegmentInfoResponse =
-          JsonUtils.stringToObject(response, ConsumingSegmentInfoReader.ConsumingSegmentsInfoMap.class);
+          getOrCreateAdminClient().getTableClient().getConsumingSegmentsInfo(getTableName(),

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/logicaltable/KafkaPartitionSubsetChaosIntegrationTest.java:
##########
@@ -594,10 +594,11 @@ private void pauseConsumptionAndWait(String realtimeTableName)
 
   private void resumeConsumptionAndWait(String realtimeTableName)
       throws Exception {
-    getControllerRequestClient().resumeConsumption(realtimeTableName);
+    getOrCreateAdminClient().getTableClient().resumeConsumption(realtimeTableName, null);
     TestUtils.waitForCondition(aVoid -> {
       try {
-        PauseStatusDetails details = getControllerRequestClient().getPauseStatusDetails(realtimeTableName);
+        PauseStatusDetails details =
+            getOrCreateAdminClient().getTableClient().getPauseStatus(realtimeTableName, PauseStatusDetails.class);

Review Comment:
   Acknowledged - these response classes (RebalanceResult, PauseStatusDetails, TableViews.TableView, ConsumingSegmentsInfoMap, ServerRebalanceJobStatusResponse, etc.) are currently in pinot-controller, which pinot-java-client cannot depend on. Moving them to pinot-common requires also moving their transitive dependencies (RebalanceSummaryResult, RebalancePreCheckerResult, TableRebalanceProgressStats, etc.) - will address in a follow-up PR dedicated to response class relocation.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Add typed admin client APIs with response classes in pinot-common; migrate tests and connectors to PinotAdminClient [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3049399963


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/resources/ZookeeperResourceTest.java:
##########
@@ -94,40 +89,29 @@ public void testZookeeperDataEndpoints()
 
     // CASE 2: Fail when sending large data in query params
     String path2 = path + "/testCase2";
-    try {
-      params = "path=" + path2 + "&data=" + URIUtils.encode(largeData) + "&expectedVersion=" + expectedVersion
-          + "&accessOption=" + accessOption;
-      ControllerTest.sendPutRequest(urlPut + "?" + params);
-      Assert.fail("Should not get here, large payload");
-    } catch (IOException e) {
-      // Expected
-    }
+    expectThrows(Exception.class,
+        () -> adminClient.getZookeeperClient().putDataWithQueryParam(path2, largeData, expectedVersion, accessOption));
 
     // CASE 3: Send large content data should return success
-    params = "path=" + path2 + "&expectedVersion=" + expectedVersion + "&accessOption=" + accessOption;
-    result = ControllerTest.sendPutRequest(urlPut + "?" + params, largeData);
+    result = adminClient.getZookeeperClient().putData(path2, largeData, expectedVersion, accessOption);
     Assert.assertTrue(result.toLowerCase().contains("successfully updated"));
 
     // validate that zk/getChildren return 2 items.
-    urlGet = TEST_INSTANCE.getControllerRequestURLBuilder().forZkGetChildren(path);
-    result = ControllerTest.sendGetRequest(urlGet);
+    result = adminClient.getZookeeperClient().getChildren(path);
 
     List<ZNRecord> recordList3 = ZookeeperResource.MAPPER.readValue(result.getBytes(StandardCharsets.UTF_8),
         new TypeReference<List<ZNRecord>>() { });
     Assert.assertEquals(recordList3.size(), 2);
 
     // CASE 4: put all children back into a different path
     String path4 = path + "/testCase4";
-    params = "path=" + path4 + "&expectedVersion=" + expectedVersion + "&accessOption=" + accessOption;
 
     // validate that zk/putChildren will insert all correctly to another path
-    urlPut = TEST_INSTANCE.getControllerRequestURLBuilder().forZkPutChildren(path);
     String encodedChildrenData = ZookeeperResource.MAPPER.writeValueAsString(recordList3);
-    result = ControllerTest.sendPutRequest(urlPut + "?" + params, encodedChildrenData);
+    result = adminClient.getZookeeperClient().putChildren(path4, encodedChildrenData, expectedVersion, accessOption);
 
     // validate that zk/getChildren from new path should result in the same recordList
-    urlGet = TEST_INSTANCE.getControllerRequestURLBuilder().forZkGetChildren(path);
-    result = ControllerTest.sendGetRequest(urlGet);
+    result = adminClient.getZookeeperClient().getChildren(path);
 

Review Comment:
   In CASE 4, the test writes children to `path4` via `putChildren(path4, ...)`, but the subsequent verification fetches children from `path` instead of `path4`. This makes the assertion unrelated to the write and can miss regressions in the `putChildren` endpoint. Fetch children from `path4` for validation.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/PinotTableRebalancer.java:
##########
@@ -20,9 +20,9 @@
 
 import com.google.common.base.Preconditions;
 import org.apache.pinot.common.metadata.ZKMetadataProvider;
-import org.apache.pinot.controller.helix.core.rebalance.RebalanceConfig;
-import org.apache.pinot.controller.helix.core.rebalance.RebalanceResult;
-import org.apache.pinot.controller.helix.core.rebalance.TableRebalanceContext;
+import org.apache.pinot.common.restlet.resources.RebalanceConfig;
+import org.apache.pinot.common.restlet.resources.RebalanceResult;
+import org.apache.pinot.common.restlet.resources.TableRebalanceContext;

Review Comment:
   The PR description says response classes were moved to `org.apache.pinot.common.response`, but the code changes import them from `org.apache.pinot.common.restlet.resources`. Please update the PR description (or the package) so consumers know the correct canonical package for these relocated response types.



##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/PinotAccessControlUserRestletResourceTest.java:
##########
@@ -91,17 +61,17 @@ public void testUpdateUserConfig()
     String username = "updateTC";
     String userConfigString =
         _userConfigBuilder.setUsername(username).setComponentType(ComponentType.CONTROLLER).build().toJsonString();
-    ControllerTest.sendPostRequest(_createUserUrl, userConfigString);
+    TEST_INSTANCE.getOrCreateAdminClient().getUserClient().createUser(userConfigString);
     // user creation should succeed
     UserConfig userConfig = getUserConfig(username, "CONTROLLER");
     assertEquals(userConfig.getRoleType().toString(), RoleType.USER.toString());
     assertTrue(BcryptUtils.checkpw("123456", userConfig.getPassword()));
     userConfig.setRole("ADMIN");
     userConfig.setPassword("654321");
 
-    JsonNode jsonResponse = JsonUtils.stringToJsonNode(ControllerTest.sendPutRequest(
-        TEST_INSTANCE.getControllerRequestURLBuilder().forUpdateUserConfig(username, "CONTROLLER", true),
-        userConfig.toString()));
+    JsonNode jsonResponse = JsonUtils.stringToJsonNode(
+        TEST_INSTANCE.getOrCreateAdminClient().getUserClient().updateUser(username, "CONTROLLER", true,
+            userConfig.toString()));
     assertTrue(jsonResponse.has("status"));

Review Comment:
   This file no longer has a dedicated test covering `createUser` validation behavior (e.g., rejecting usernames with '.' / spaces and failing on duplicate user creation). The remaining tests only cover update/delete flows and assume user creation succeeds, which weakens coverage for user-creation input validation and error handling. Consider re-adding a focused create-user test using `UserAdminClient.createUser(...)` and asserting the expected exception/messages for invalid and duplicate usernames.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038798262


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotClusterAdminClient.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.client.admin;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Client for cluster-level administration operations.
+ */
+public class PinotClusterAdminClient {
+  private final PinotAdminTransport _transport;
+  private final String _controllerAddress;
+  private final Map<String, String> _headers;
+
+  public PinotClusterAdminClient(PinotAdminTransport transport, String controllerAddress,
+      Map<String, String> headers) {
+    _transport = transport;
+    _controllerAddress = controllerAddress;
+    _headers = headers;
+  }
+

Review Comment:
   1. Add an api to update a specific config with it's value



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038859621


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java:
##########
@@ -351,10 +352,19 @@ private TableView getTableIdealState(String tableNameOptType, @Nullable TableTyp
   private TableView getTableExternalView(String tableNameOptType, @Nullable TableType tableType) {
     TableView tableView = new TableView();
     if (tableType == null || tableType == TableType.OFFLINE) {
-      tableView._offline = getExternalView(tableNameOptType, TableType.OFFLINE);
+      Map<String, Map<String, String>> external = getExternalView(tableNameOptType, TableType.OFFLINE);
+      if (external == null || external.isEmpty()) {
+        // Fallback to ideal state if external view is not yet materialized.
+        external = getIdealState(tableNameOptType, TableType.OFFLINE);

Review Comment:
   no fallback to idealstate.
   



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/TableViews.java:
##########
@@ -351,10 +352,19 @@ private TableView getTableIdealState(String tableNameOptType, @Nullable TableTyp
   private TableView getTableExternalView(String tableNameOptType, @Nullable TableType tableType) {
     TableView tableView = new TableView();
     if (tableType == null || tableType == TableType.OFFLINE) {
-      tableView._offline = getExternalView(tableNameOptType, TableType.OFFLINE);
+      Map<String, Map<String, String>> external = getExternalView(tableNameOptType, TableType.OFFLINE);
+      if (external == null || external.isEmpty()) {
+        // Fallback to ideal state if external view is not yet materialized.
+        external = getIdealState(tableNameOptType, TableType.OFFLINE);
+      }
+      tableView._offline = external;
     }
     if (tableType == null || tableType == TableType.REALTIME) {
-      tableView._realtime = getExternalView(tableNameOptType, TableType.REALTIME);
+      Map<String, Map<String, String>> external = getExternalView(tableNameOptType, TableType.REALTIME);
+      if (external == null || external.isEmpty()) {
+        external = getIdealState(tableNameOptType, TableType.REALTIME);

Review Comment:
   no fallback to idealstate.
   



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038775658


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotSchemaAdminClient.java:
##########
@@ -69,17 +76,32 @@ public String getSchemasInfo()
   }
 
   /**
-   * Gets a specific schema by name.
+   * Gets a specific schema as a JSON string.
    *
    * @param schemaName Name of the schema
    * @return Schema configuration as JSON string
    * @throws PinotAdminException If the request fails
    */
-  public String getSchema(String schemaName)
+  public String getSchemaString(String schemaName)

Review Comment:
   revert the method name to getSchema



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3038956686


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/UrlAuthRealtimeIntegrationTest.java:
##########
@@ -150,7 +149,7 @@ protected Map<String, String> getPinotClientTransportHeaders() {
   public void testUnauthenticatedFailure()
       throws IOException {
     sendDeleteRequest(

Review Comment:
   should move all `sendDeleteRequest` to corresponding admin clients



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3039278866


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/FlinkQuickStart.java:
##########
@@ -79,12 +76,11 @@ public static void main(String[] args)
     execEnv.setParallelism(2);
     DataStream<Row> srcDs = execEnv.fromCollection(data).returns(TEST_TYPE_INFO).keyBy(r -> r.getField(0));
 
-    HttpClient httpClient = HttpClient.getInstance();
-    ControllerRequestClient client = new ControllerRequestClient(
-        ControllerRequestURLBuilder.baseUrl(DEFAULT_CONTROLLER_URL), httpClient);
-    Schema schema = PinotConnectionUtils.getSchema(client, "starbucksStores");
-    TableConfig tableConfig = PinotConnectionUtils.getTableConfig(client, "starbucksStores", "OFFLINE");
-    srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
-    execEnv.execute();
+    try (PinotAdminClient client = new PinotAdminClient("localhost:9000")) {
+      Schema schema = client.getSchemaClient().getSchemaObject("starbucksStores");
+      TableConfig tableConfig = client.getTableClient().getTableConfigObject("starbucksStores", "OFFLINE");
+      srcDs.addSink(new PinotSinkFunction<>(new FlinkRowGenericRowConverter(TEST_TYPE_INFO), tableConfig, schema));
+      execEnv.execute();

Review Comment:
   Fixed - FlinkQuickStart now uses DEFAULT_CONTROLLER_ADDRESS constant.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,120 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }

Review Comment:
   Fixed - batchConfigMapStr is now serialized using Jackson ObjectMapper.writeValueAsString() for proper JSON encoding.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,120 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromFile endpoint.
+   */
+  public int ingestFromFile(String tableNameWithType, Map<String, String> batchConfigMap, File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromFileUrl(tableNameWithType, batchConfigMap), inputFile);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromURI endpoint.
+   */
+  public int ingestFromUri(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri,
+      File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromUriUrl(tableNameWithType, batchConfigMap, sourceUri), inputFile);
+  }
+
+  /**
+   * Posts a multipart file to an explicit URL.
+   */
+  public int postFile(String url, File inputFile)
+      throws PinotAdminException {
+    HttpEntity reqEntity =
+        MultipartEntityBuilder.create().addPart("file", new FileBody(inputFile.getAbsoluteFile())).build();
+    return execute(url, reqEntity);
+  }
+
+  /**
+   * Posts a plain string body to an explicit URL.
+   */
+  public int postString(String url, String body)
+      throws PinotAdminException {
+    return execute(url, new StringEntity(body));
+  }
+
+  private int execute(String url, HttpEntity entity)
+      throws PinotAdminException {
+    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+      HttpPost httpPost = new HttpPost(url);
+      for (Map.Entry<String, String> header : _headers.entrySet()) {
+        httpPost.setHeader(header.getKey(), header.getValue());
+      }
+      httpPost.setEntity(entity);
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        return response.getCode();
+      }

Review Comment:
   Fixed - PinotFileIngestClient.execute() now applies the SSLContext from the transport when building the HTTP client.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }

Review Comment:
   Fixed - switched from manual string concatenation to Jackson ObjectMapper for proper JSON serialization.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/admin/PinotFileIngestClient.java:
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.client.admin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.FileBody;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+
+/**
+ * Explicit client for Pinot controller endpoints that accept file or raw-body uploads.
+ */
+public class PinotFileIngestClient extends AbstractPinotAdminClient {
+  public PinotFileIngestClient(PinotAdminTransport transport, String controllerAddress, Map<String, String> headers) {
+    super(transport, controllerAddress, headers);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromFile.
+   */
+  public String buildIngestFromFileUrl(String tableNameWithType, Map<String, String> batchConfigMap) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromFile?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Builds the ingestion URL for ingestFromURI.
+   */
+  public String buildIngestFromUriUrl(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri) {
+    String batchConfigMapStr =
+        batchConfigMap.entrySet().stream().map(e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"")
+            .collect(java.util.stream.Collectors.joining(",", "{", "}"));
+    String baseUrl = _transport.getScheme() + "://" + _controllerAddress;
+    return baseUrl + "/ingestFromURI?tableNameWithType=" + tableNameWithType + "&batchConfigMapStr="
+        + URLEncoder.encode(batchConfigMapStr, StandardCharsets.UTF_8) + "&sourceURIStr="
+        + URLEncoder.encode(sourceUri, StandardCharsets.UTF_8);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromFile endpoint.
+   */
+  public int ingestFromFile(String tableNameWithType, Map<String, String> batchConfigMap, File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromFileUrl(tableNameWithType, batchConfigMap), inputFile);
+  }
+
+  /**
+   * Posts a multipart file upload to the ingestFromURI endpoint.
+   */
+  public int ingestFromUri(String tableNameWithType, Map<String, String> batchConfigMap, String sourceUri,
+      File inputFile)
+      throws PinotAdminException {
+    return postFile(buildIngestFromUriUrl(tableNameWithType, batchConfigMap, sourceUri), inputFile);
+  }
+
+  /**
+   * Posts a multipart file to an explicit URL.
+   */
+  public int postFile(String url, File inputFile)
+      throws PinotAdminException {
+    HttpEntity reqEntity =
+        MultipartEntityBuilder.create().addPart("file", new FileBody(inputFile.getAbsoluteFile())).build();
+    return execute(url, reqEntity);
+  }
+
+  /**
+   * Posts a plain string body to an explicit URL.
+   */
+  public int postString(String url, String body)
+      throws PinotAdminException {
+    return execute(url, new StringEntity(body));
+  }
+
+  private int execute(String url, HttpEntity entity)
+      throws PinotAdminException {
+    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+      HttpPost httpPost = new HttpPost(url);
+      for (Map.Entry<String, String> header : _headers.entrySet()) {
+        httpPost.setHeader(header.getKey(), header.getValue());
+      }
+      httpPost.setEntity(entity);
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        return response.getCode();
+      }
+    } catch (IOException e) {
+      throw new PinotAdminException("Failed to execute file ingest request to " + url, e);
+    }

Review Comment:
   Fixed - buildHttpClient() now applies SSLContext from transport when available.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/LaunchBackfillIngestionJobCommand.java:
##########
@@ -102,7 +102,7 @@ public boolean execute()
       Properties transportProperties = getTransportProperties(spec);
       PinotAdminClient adminClient = new PinotAdminClient(controllerAddress, transportProperties, authHeader);
 
-      _pinotSegmentApiClient = adminClient.getSegmentApiClient();
+      _pinotSegmentAdminClient = adminClient.getSegmentClient();
       // 1. Fetch existing segments that need to be backfilled (to be replaced)

Review Comment:
   Fixed - PinotAdminClient is now stored as a field and closed in a finally block.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/OperateClusterConfigCommand.java:
##########
@@ -144,36 +87,34 @@ public String run()
     if (StringUtils.isEmpty(_config) && !_operation.equalsIgnoreCase("GET")) {
       throw new UnsupportedOperationException("Empty config: " + _config);
     }
-    String clusterConfigUrl =
-        _controllerProtocol + "://" + _controllerHost + ":" + _controllerPort + "/cluster/configs";
-    List<Header> headers = AuthProviderUtils.makeAuthHeaders(
-        AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user,
-        _password));
-    switch (_operation.toUpperCase()) {
-      case "ADD":
-      case "UPDATE":
-        String[] splits = _config.split("=");
-        if (splits.length != 2) {
-          throw new UnsupportedOperationException(
-              "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
-        }
-        String request = JsonUtils.objectToString(Collections.singletonMap(splits[0], splits[1]));
-        return sendRequest("POST", clusterConfigUrl, request, headers);
-      case "GET":
-        String response = sendRequest("GET", clusterConfigUrl, null, headers);
-        JsonNode jsonNode = JsonUtils.stringToJsonNode(response);
-        Iterator<String> fieldNamesIterator = jsonNode.fieldNames();
-        String results = "";
-        while (fieldNamesIterator.hasNext()) {
-          String key = fieldNamesIterator.next();
-          String value = jsonNode.get(key).textValue();
-          results += String.format("%s=%s\n", key, value);
-        }
-        return results;
-      case "DELETE":
-        return sendRequest("DELETE", String.format("%s/%s", clusterConfigUrl, _config), null, headers);
-      default:
-        throw new UnsupportedOperationException("Unsupported operation: " + _operation);
+    String normalizedOperation = _operation.toUpperCase(Locale.ROOT);
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      switch (normalizedOperation) {
+        case "ADD":
+        case "UPDATE":
+          String[] splits = _config.split("=");
+          if (splits.length != 2) {
+            throw new UnsupportedOperationException(
+                "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
+          }
+          String request = JsonUtils.objectToString(java.util.Collections.singletonMap(splits[0], splits[1]));
+          return adminClient.getClusterClient().updateClusterConfig(request);
+        case "GET":
+          String response = adminClient.getClusterClient().getClusterConfigs();
+          JsonNode jsonNode = JsonUtils.stringToJsonNode(response);
+          StringBuilder results = new StringBuilder();
+          jsonNode.fieldNames().forEachRemaining(key -> {
+            String value = jsonNode.get(key).textValue();
+            results.append(String.format("%s=%s%n", key, value));
+          });
+          return results.toString();
+        case "DELETE":
+          return adminClient.getClusterClient().deleteClusterConfig(_config);
+        default:
+          throw new UnsupportedOperationException("Unsupported operation: " + _operation);
+      }
+    } catch (PinotAdminException e) {
+      throw new RuntimeException("Failed to operate on cluster config", e);

Review Comment:
   Acknowledged - will let PinotAdminException propagate instead of wrapping in RuntimeException in a follow-up.



##########
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/OperateClusterConfigCommand.java:
##########
@@ -144,36 +87,34 @@ public String run()
     if (StringUtils.isEmpty(_config) && !_operation.equalsIgnoreCase("GET")) {
       throw new UnsupportedOperationException("Empty config: " + _config);
     }
-    String clusterConfigUrl =
-        _controllerProtocol + "://" + _controllerHost + ":" + _controllerPort + "/cluster/configs";
-    List<Header> headers = AuthProviderUtils.makeAuthHeaders(
-        AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, _authToken, _user,
-        _password));
-    switch (_operation.toUpperCase()) {
-      case "ADD":
-      case "UPDATE":
-        String[] splits = _config.split("=");
-        if (splits.length != 2) {
-          throw new UnsupportedOperationException(
-              "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
-        }
-        String request = JsonUtils.objectToString(Collections.singletonMap(splits[0], splits[1]));
-        return sendRequest("POST", clusterConfigUrl, request, headers);
-      case "GET":
-        String response = sendRequest("GET", clusterConfigUrl, null, headers);
-        JsonNode jsonNode = JsonUtils.stringToJsonNode(response);
-        Iterator<String> fieldNamesIterator = jsonNode.fieldNames();
-        String results = "";
-        while (fieldNamesIterator.hasNext()) {
-          String key = fieldNamesIterator.next();
-          String value = jsonNode.get(key).textValue();
-          results += String.format("%s=%s\n", key, value);
-        }
-        return results;
-      case "DELETE":
-        return sendRequest("DELETE", String.format("%s/%s", clusterConfigUrl, _config), null, headers);
-      default:
-        throw new UnsupportedOperationException("Unsupported operation: " + _operation);
+    String normalizedOperation = _operation.toUpperCase(Locale.ROOT);
+    try (PinotAdminClient adminClient = getPinotAdminClient()) {
+      switch (normalizedOperation) {
+        case "ADD":
+        case "UPDATE":
+          String[] splits = _config.split("=");
+          if (splits.length != 2) {
+            throw new UnsupportedOperationException(
+                "Bad config: " + _config + ". Please follow the pattern of [Config Key]=[Config Value]");
+          }
+          String request = JsonUtils.objectToString(java.util.Collections.singletonMap(splits[0], splits[1]));
+          return adminClient.getClusterClient().updateClusterConfig(request);

Review Comment:
   Fixed in this PR - the FQCN issue in PinotClusterAdminClient has been addressed. The OperateClusterConfigCommand uses the admin client's updateClusterConfig(key, value) which handles serialization internally.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041154979


##########
pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/BaseClusterIntegrationTest.java:
##########
@@ -1166,26 +1169,25 @@ protected long getLongCellValue(JsonNode jsonNode, int colIndex, int rowIndex) {
 
   protected JsonNode getColumnIndexSize(String column)
       throws Exception {
-    return JsonUtils.stringToJsonNode(
-            sendGetRequest(_controllerRequestURLBuilder.forTableAggregateMetadata(getTableName(), List.of(column))))
-        .get("columnIndexSizeMap").get(column);
+    TableMetadataInfo metadata = getOrCreateAdminClient().getTableClient()
+        .getAggregateMetadata(getTableName(), String.join(",", List.of(column)));
+    return JsonUtils.objectToJsonNode(metadata).get("columnIndexSizeMap").get(column);
   }
 
   /**
    * Get all segment names for a given tableName and tableType.
    */
   protected List<String> getSegmentNames(String tableName, @Nullable String tableType)
       throws Exception {
-    return getControllerRequestClient().listSegments(tableName, tableType, true);
+    return getOrCreateAdminClient().getSegmentClient().listSegments(tableName, tableType, true);
   }
 
   protected List<ValidDocIdsMetadataInfo> getValidDocIdsMetadata(String tableNameWithType,
       ValidDocIdsType validDocIdsType)
       throws Exception {
 
-    StringBuilder urlBuilder = new StringBuilder(
-        _controllerRequestURLBuilder.forValidDocIdsMetadata(tableNameWithType, validDocIdsType.toString()));
-    String responseString = sendGetRequest(urlBuilder.toString());
+    String responseString = getOrCreateAdminClient().getTableClient()
+        .getValidDocIdsMetadata(tableNameWithType, validDocIdsType.toString());

Review Comment:
   getValidDocIdsMetadata should return List<ValidDocIdsMetadataInfo> class directly



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041164939


##########
pinot-controller/src/test/java/org/apache/pinot/controller/api/TableViewsTest.java:
##########
@@ -166,15 +188,22 @@ public void testHybridTableState(String state)
 
   private TableViews.TableView getTableView(String tableName, String view, String tableType)
       throws Exception {
-    return JsonUtils.stringToObject(
-        sendGetRequest(DEFAULT_INSTANCE.getControllerRequestURLBuilder().forTableView(tableName, view, tableType)),
-        TableViews.TableView.class);
+    PinotAdminClient adminClient = getOrCreateAdminClient();
+    return adminClient.getTableClient().getTableView(tableName, view, tableType, TableViews.TableView.class);

Review Comment:
   getTableView should return TableView class directly



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041117493


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/TenantRebalanceIntegrationTest.java:
##########
@@ -32,9 +32,16 @@
 
 public class TenantRebalanceIntegrationTest extends BaseHybridClusterIntegrationTest {
 
-  private String getRebalanceUrl() {
-    return StringUtil.join("/", getControllerRequestURLBuilder().getBaseUrl(), "tenants", getServerTenant(),
-        "rebalance");
+  private TenantRebalanceResult rebalanceTenant(TenantRebalanceConfig config, @Nullable Map<String, String> queryParams)
+      throws Exception {
+    return getOrCreateAdminClient().getTenantClient()
+        .rebalanceTenantWithConfig(config.getTenantName(), JsonUtils.objectToString(config), queryParams,

Review Comment:
   rebalanceTenantWithConfig() method should directly return TenantRebalanceResult



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Migrate tests and connector to PinotAdminClient [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #17167:
URL: https://github.com/apache/pinot/pull/17167#discussion_r3041150076


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/logicaltable/KafkaPartitionSubsetChaosIntegrationTest.java:
##########
@@ -594,10 +594,11 @@ private void pauseConsumptionAndWait(String realtimeTableName)
 
   private void resumeConsumptionAndWait(String realtimeTableName)
       throws Exception {
-    getControllerRequestClient().resumeConsumption(realtimeTableName);
+    getOrCreateAdminClient().getTableClient().resumeConsumption(realtimeTableName, null);
     TestUtils.waitForCondition(aVoid -> {
       try {
-        PauseStatusDetails details = getControllerRequestClient().getPauseStatusDetails(realtimeTableName);
+        PauseStatusDetails details =
+            getOrCreateAdminClient().getTableClient().getPauseStatus(realtimeTableName, PauseStatusDetails.class);

Review Comment:
   getPauseStatus should return PauseStatusDetails class directly



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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