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

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


The following commit(s) were added to refs/heads/master by this push:
     new f141cd21d8 supporting additional headers (#13417)
f141cd21d8 is described below

commit f141cd21d88ff983ac557865b1398f327e2d96dd
Author: hubert <4006002+hdu...@users.noreply.github.com>
AuthorDate: Fri Aug 9 13:32:20 2024 -0400

    supporting additional headers (#13417)
---
 .../command/AbstractDatabaseBaseAdminCommand.java  | 148 +++++++++++++++++++++
 .../tools/admin/command/AddSchemaCommand.java      |  90 ++-----------
 .../pinot/tools/admin/command/AddTableCommand.java | 110 ++-------------
 .../tools/admin/command/DeleteSchemaCommand.java   |  82 +-----------
 .../tools/admin/command/DeleteTableCommand.java    |  88 +-----------
 5 files changed, 175 insertions(+), 343 deletions(-)

diff --git 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractDatabaseBaseAdminCommand.java
 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractDatabaseBaseAdminCommand.java
new file mode 100644
index 0000000000..5cd303aa5b
--- /dev/null
+++ 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractDatabaseBaseAdminCommand.java
@@ -0,0 +1,148 @@
+/**
+ * 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.tools.admin.command;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import javax.net.ssl.SSLContext;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.message.BasicHeader;
+import org.apache.pinot.common.auth.AuthProviderUtils;
+import org.apache.pinot.common.utils.ClientSSLContextGenerator;
+import org.apache.pinot.spi.auth.AuthProvider;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.tools.Command;
+import picocli.CommandLine;
+
+
+public abstract class AbstractDatabaseBaseAdminCommand extends 
AbstractBaseAdminCommand implements Command {
+  @CommandLine.Option(names = {"-controllerHost"}, required = false, 
description = "Host name for controller.")
+  protected String _controllerHost;
+
+  @CommandLine.Option(names = {"-controllerPort"}, required = false, 
description = "Port number for controller.")
+  protected String _controllerPort = DEFAULT_CONTROLLER_PORT;
+
+  @CommandLine.Option(names = {"-controllerProtocol"}, required = false, 
description = "Protocol for controller.")
+  protected String _controllerProtocol = CommonConstants.HTTP_PROTOCOL;
+
+  @CommandLine.Option(names = {"-user"}, required = false, description = 
"Username for basic auth.")
+  protected String _user;
+
+  @CommandLine.Option(names = {"-password"}, required = false, description = 
"Password for basic auth.")
+  protected String _password;
+
+  @CommandLine.Option(names = {"-authToken"}, required = false, description = 
"Http auth token.")
+  protected String _authToken;
+
+  @CommandLine.Option(names = {"-authTokenUrl"}, required = false, description 
= "Http auth token url.")
+  protected String _authTokenUrl;
+
+  protected AuthProvider _authProvider;
+
+  @CommandLine.Option(names = {"-exec"}, required = false, description = 
"Execute the command.")
+  protected boolean _exec;
+
+  @CommandLine.Option(names = {"-skipControllerCertValidation"}, required = 
false, description = "Whether to skip"
+      + " controller certification validation.")
+  private boolean _skipControllerCertValidation = false;
+
+  @CommandLine.Option(names = {"-database"}, required = false, description = 
"Corresponding database.")
+  protected String _database;
+
+  @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = 
false, help = true, description = "Print "
+      + "this message.")
+  private boolean _help = false;
+
+  public AbstractDatabaseBaseAdminCommand setControllerHost(String 
controllerHost) {
+    _controllerHost = controllerHost;
+    return this;
+  }
+
+  public AbstractDatabaseBaseAdminCommand setControllerPort(String 
controllerPort) {
+    _controllerPort = controllerPort;
+    return this;
+  }
+
+  public AbstractDatabaseBaseAdminCommand setControllerProtocol(String 
controllerProtocol) {
+    _controllerProtocol = controllerProtocol;
+    return this;
+  }
+
+  public AbstractDatabaseBaseAdminCommand setUser(String user) {
+    _user = user;
+    return this;
+  }
+
+  public AbstractDatabaseBaseAdminCommand setPassword(String password) {
+    _password = password;
+    return this;
+  }
+
+  public AbstractDatabaseBaseAdminCommand setAuthProvider(AuthProvider 
authProvider) {
+    _authProvider = authProvider;
+    return this;
+  }
+
+  public AbstractDatabaseBaseAdminCommand setDatabase(String database) {
+    _database = database;
+    return this;
+  }
+
+  protected SSLContext makeTrustAllSSLContext() {
+    if (_skipControllerCertValidation) {
+      PinotConfiguration trustAllSslConfig = new PinotConfiguration();
+      return new ClientSSLContextGenerator(trustAllSslConfig).generate();
+    } else {
+      return null;
+    }
+  }
+
+  protected List<Header> getHeaders() {
+    List<Header> headers = AuthProviderUtils.makeAuthHeaders(
+        AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, 
_authToken, _user, _password));
+    headers.add(new BasicHeader("database", _database));
+    return headers;
+  }
+
+  protected Map<String, String> getHeadersAsMap() {
+    return getHeaders().stream().collect(Collectors.toMap(Header::getName, 
Header::getValue));
+  }
+
+  public AbstractDatabaseBaseAdminCommand setExecute(boolean exec) {
+    _exec = exec;
+    return this;
+  }
+
+  @Override
+  public boolean getHelp() {
+    return _help;
+  }
+
+  @Override
+  public String toString() {
+    String retString =
+        (" -controllerProtocol " + _controllerProtocol + " -controllerHost " + 
_controllerHost + " -controllerPort "
+            + _controllerPort + " -controllerProtocol " + _controllerProtocol 
+ " -database " + _database + " -user "
+            + _user + " -password " + "[hidden]");
+
+    return ((_exec) ? (retString + " -exec") : retString);
+  }
+}
diff --git 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddSchemaCommand.java
 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddSchemaCommand.java
index 10c7e92e7b..acfc1979d0 100644
--- 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddSchemaCommand.java
+++ 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddSchemaCommand.java
@@ -22,31 +22,18 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.util.Collections;
-import org.apache.pinot.common.auth.AuthProviderUtils;
 import org.apache.pinot.common.utils.FileUploadDownloadClient;
-import org.apache.pinot.spi.auth.AuthProvider;
 import org.apache.pinot.spi.data.Schema;
-import org.apache.pinot.spi.utils.CommonConstants;
 import org.apache.pinot.spi.utils.NetUtils;
-import org.apache.pinot.tools.Command;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import picocli.CommandLine;
 
 
 @CommandLine.Command(name = "AddSchema")
-public class AddSchemaCommand extends AbstractBaseAdminCommand implements 
Command {
+public class AddSchemaCommand extends AbstractDatabaseBaseAdminCommand {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(AddSchemaCommand.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 = {"-schemaFile"}, required = true, description = 
"Path to schema file.")
   private String _schemaFile = null;
 
@@ -58,32 +45,6 @@ public class AddSchemaCommand extends 
AbstractBaseAdminCommand implements Comman
       + "the schema exists.")
   private boolean _force = false;
 
-  @CommandLine.Option(names = {"-exec"}, required = false, description = 
"Execute the command.")
-  private boolean _exec;
-
-  @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;
-
-  @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = 
false, help = true,
-      description = "Print this message.")
-  private boolean _help = false;
-
-  private AuthProvider _authProvider;
-
-  @Override
-  public boolean getHelp() {
-    return _help;
-  }
-
   @Override
   public String description() {
     return "Add schema specified in the schema file to the controller";
@@ -96,32 +57,16 @@ public class AddSchemaCommand extends 
AbstractBaseAdminCommand implements Comman
 
   @Override
   public String toString() {
-    String retString = ("AddSchema -controllerProtocol " + _controllerProtocol 
+ " -controllerHost " + _controllerHost
-        + " -controllerPort " + _controllerPort + " -schemaFile " + 
_schemaFile + " -override " + _override + " _force "
-        + _force + " -user " + _user + " -password " + "[hidden]");
+    String retString = (getName() + " -schemaFile " + _schemaFile + " 
-override " + _override + " _force " + _force
+        + super.toString());
 
-    return ((_exec) ? (retString + " -exec") : retString);
+    return retString;
   }
 
   @Override
   public void cleanup() {
   }
 
-  public AddSchemaCommand setControllerHost(String controllerHost) {
-    _controllerHost = controllerHost;
-    return this;
-  }
-
-  public AddSchemaCommand setControllerPort(String controllerPort) {
-    _controllerPort = controllerPort;
-    return this;
-  }
-
-  public AddSchemaCommand setControllerProtocol(String controllerProtocol) {
-    _controllerProtocol = controllerProtocol;
-    return this;
-  }
-
   public AddSchemaCommand setSchemaFilePath(String schemaFilePath) {
     _schemaFile = schemaFilePath;
     return this;
@@ -137,23 +82,6 @@ public class AddSchemaCommand extends 
AbstractBaseAdminCommand implements Comman
     return this;
   }
 
-  public void setUser(String user) {
-    _user = user;
-  }
-
-  public void setPassword(String password) {
-    _password = password;
-  }
-
-  public void setAuthProvider(AuthProvider authProvider) {
-    _authProvider = authProvider;
-  }
-
-  public AddSchemaCommand setExecute(boolean exec) {
-    _exec = exec;
-    return this;
-  }
-
   @Override
   public boolean execute()
       throws Exception {
@@ -175,13 +103,11 @@ public class AddSchemaCommand extends 
AbstractBaseAdminCommand implements Comman
 
     Schema schema = Schema.fromFile(schemaFile);
     try (FileUploadDownloadClient fileUploadDownloadClient = new 
FileUploadDownloadClient()) {
-      URI schemaURI = FileUploadDownloadClient
-          .getUploadSchemaURI(_controllerProtocol, _controllerHost, 
Integer.parseInt(_controllerPort));
+      URI schemaURI = 
FileUploadDownloadClient.getUploadSchemaURI(_controllerProtocol, 
_controllerHost,
+          Integer.parseInt(_controllerPort));
       schemaURI = new URI(schemaURI + "?override=" + _override + "&force=" + 
_force);
-      fileUploadDownloadClient.addSchema(schemaURI,
-          schema.getSchemaName(), schemaFile, 
AuthProviderUtils.makeAuthHeaders(
-              AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, 
_authToken,
-              _user, _password)), Collections.emptyList());
+      fileUploadDownloadClient.addSchema(schemaURI, schema.getSchemaName(), 
schemaFile, getHeaders(),
+          Collections.emptyList());
     } catch (Exception e) {
       LOGGER.error("Got Exception to upload Pinot Schema: {}", 
schema.getSchemaName(), e);
       return false;
diff --git 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java
 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java
index 078196b29d..389a1463f6 100644
--- 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java
+++ 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java
@@ -23,21 +23,14 @@ import com.google.common.base.Preconditions;
 import java.io.File;
 import java.io.IOException;
 import java.util.concurrent.Callable;
-import javax.net.ssl.SSLContext;
-import org.apache.pinot.common.auth.AuthProviderUtils;
-import org.apache.pinot.common.utils.ClientSSLContextGenerator;
-import org.apache.pinot.spi.auth.AuthProvider;
 import org.apache.pinot.spi.config.TableConfigs;
 import org.apache.pinot.spi.config.table.TableConfig;
 import org.apache.pinot.spi.config.table.TableType;
 import org.apache.pinot.spi.data.Schema;
-import org.apache.pinot.spi.env.PinotConfiguration;
-import org.apache.pinot.spi.utils.CommonConstants;
 import org.apache.pinot.spi.utils.JsonUtils;
 import org.apache.pinot.spi.utils.NetUtils;
 import org.apache.pinot.spi.utils.builder.ControllerRequestURLBuilder;
 import org.apache.pinot.spi.utils.builder.TableNameBuilder;
-import org.apache.pinot.tools.Command;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import picocli.CommandLine;
@@ -48,7 +41,7 @@ import picocli.CommandLine;
  *
  */
 @CommandLine.Command(name = "AddTable")
-public class AddTableCommand extends AbstractBaseAdminCommand implements 
Command {
+public class AddTableCommand extends AbstractDatabaseBaseAdminCommand {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(AddTableCommand.class);
 
   @CommandLine.Option(names = {"-tableConfigFile", "-tableConf", 
"-tableConfig", "-filePath"}, description = "Path to"
@@ -69,51 +62,12 @@ public class AddTableCommand extends 
AbstractBaseAdminCommand implements Command
       + " table schema file.")
   private String _schemaFile = null;
 
-  @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 = {"-update"}, required = false, description = 
"Update the existing table instead of "
       + "creating new one")
   private boolean _update = false;
 
-  @CommandLine.Option(names = {"-exec"}, required = false, description = 
"Execute the command.")
-  private boolean _exec;
-
-  @CommandLine.Option(names = {"-skipControllerCertValidation"}, required = 
false, description = "Whether to skip"
-      + " controller certification validation.")
-  private boolean _skipControllerCertValidation = false;
-
-  @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;
-
-  @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = 
false, help = true, description = "Print "
-      + "this message.")
-  private boolean _help = false;
-
   private String _controllerAddress;
 
-  private AuthProvider _authProvider;
-
-  @Override
-  public boolean getHelp() {
-    return _help;
-  }
-
   @Override
   public String getName() {
     return "AddTable";
@@ -126,10 +80,12 @@ public class AddTableCommand extends 
AbstractBaseAdminCommand implements Command
 
   @Override
   public String toString() {
-    return "AddTable -tableConfigFile " + _tableConfigFile + " 
-offlineTableConfigFile " + _offlineTableConfigFile
-        + " -realtimeTableConfigFile " + _realtimeTableConfigFile + " 
-schemaFile " + _schemaFile
-        + " -controllerProtocol " + _controllerProtocol + " -controllerHost " 
+ _controllerHost + " -controllerPort "
-        + _controllerPort + " -user " + _user + " -password [hidden]" + (_exec 
? " -exec" : "");
+    String retString =
+        (getName() + " -tableConfigFile " + _tableConfigFile + " 
-offlineTableConfigFile " + _offlineTableConfigFile
+            + " -realtimeTableConfigFile " + _realtimeTableConfigFile + " 
-schemaFile " + _schemaFile
+            + super.toString());
+
+    return retString;
   }
 
   @Override
@@ -156,47 +112,10 @@ public class AddTableCommand extends 
AbstractBaseAdminCommand implements Command
     return this;
   }
 
-  public AddTableCommand setControllerHost(String controllerHost) {
-    _controllerHost = controllerHost;
-    return this;
-  }
-
-  public AddTableCommand setControllerPort(String controllerPort) {
-    _controllerPort = controllerPort;
-    return this;
-  }
-
-  public AddTableCommand setControllerProtocol(String controllerProtocol) {
-    _controllerProtocol = controllerProtocol;
-    return this;
-  }
-
-  public AddTableCommand setUser(String user) {
-    _user = user;
-    return this;
-  }
-
-  public AddTableCommand setPassword(String password) {
-    _password = password;
-    return this;
-  }
-
-  public AddTableCommand setExecute(boolean exec) {
-    _exec = exec;
-    return this;
-  }
-
-  public AddTableCommand setAuthProvider(AuthProvider authProvider) {
-    _authProvider = authProvider;
-    return this;
-  }
-
   public boolean sendTableCreationRequest(JsonNode node)
       throws IOException {
     String res = AbstractBaseAdminCommand.sendRequest("POST",
-        
ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTableConfigsCreate(),
 node.toString(),
-        AuthProviderUtils.makeAuthHeaders(
-            AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, 
_authToken, _user, _password)),
+        
ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTableConfigsCreate(),
 node.toString(), getHeaders(),
         makeTrustAllSSLContext());
     LOGGER.info(res);
     return res.contains("successfully added");
@@ -206,22 +125,11 @@ public class AddTableCommand extends 
AbstractBaseAdminCommand implements Command
       throws IOException {
     String res = AbstractBaseAdminCommand.sendRequest("PUT",
         
ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTableConfigsUpdate(tableName),
 node.toString(),
-        AuthProviderUtils.makeAuthHeaders(
-            AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, 
_authToken, _user, _password)),
-        makeTrustAllSSLContext());
+        getHeaders(), makeTrustAllSSLContext());
     LOGGER.info(res);
     return res.contains("TableConfigs updated");
   }
 
-  private SSLContext makeTrustAllSSLContext() {
-    if (_skipControllerCertValidation) {
-      PinotConfiguration trustAllSslConfig = new PinotConfiguration();
-      return new ClientSSLContextGenerator(trustAllSslConfig).generate();
-    } else {
-      return null;
-    }
-  }
-
   @Override
   public boolean execute()
       throws Exception {
diff --git 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteSchemaCommand.java
 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteSchemaCommand.java
index c0dd09c3ff..437111e5d3 100644
--- 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteSchemaCommand.java
+++ 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteSchemaCommand.java
@@ -18,60 +18,21 @@
  */
 package org.apache.pinot.tools.admin.command;
 
-import java.util.Collections;
 import org.apache.pinot.common.auth.AuthProviderUtils;
 import org.apache.pinot.common.utils.FileUploadDownloadClient;
-import org.apache.pinot.spi.auth.AuthProvider;
-import org.apache.pinot.spi.utils.CommonConstants;
 import org.apache.pinot.spi.utils.NetUtils;
-import org.apache.pinot.tools.Command;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import picocli.CommandLine;
 
 
 @CommandLine.Command(name = "DeleteSchema")
-public class DeleteSchemaCommand extends AbstractBaseAdminCommand implements 
Command {
+public class DeleteSchemaCommand extends AbstractDatabaseBaseAdminCommand {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(DeleteSchemaCommand.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 = {"-schemaName"}, required = true, description = 
"Schema name.")
   private String _schemaName = null;
 
-  @CommandLine.Option(names = {"-exec"}, required = false, description = 
"Execute the command.")
-  private boolean _exec;
-
-  @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;
-
-  @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = 
false, help = true, description = "Print "
-      + "this message.")
-  private boolean _help = false;
-
-  private AuthProvider _authProvider;
-
-  @Override
-  public boolean getHelp() {
-    return _help;
-  }
-
   @Override
   public String description() {
     return "Delete schema specified via name";
@@ -84,55 +45,18 @@ public class DeleteSchemaCommand extends 
AbstractBaseAdminCommand implements Com
 
   @Override
   public String toString() {
-    String retString =
-        ("DeleteSchema -controllerProtocol " + _controllerProtocol + " 
-controllerHost " + _controllerHost
-            + " -controllerPort " + _controllerPort + " -schemaName " + 
_schemaName + " -user " + _user + " -password "
-            + "[hidden]");
-
-    return ((_exec) ? (retString + " -exec") : retString);
+    return (getName() + " -schemaName " + _schemaName + super.toString());
   }
 
   @Override
   public void cleanup() {
   }
 
-  public DeleteSchemaCommand setControllerHost(String controllerHost) {
-    _controllerHost = controllerHost;
-    return this;
-  }
-
-  public DeleteSchemaCommand setControllerPort(String controllerPort) {
-    _controllerPort = controllerPort;
-    return this;
-  }
-
-  public DeleteSchemaCommand setControllerProtocol(String controllerProtocol) {
-    _controllerProtocol = controllerProtocol;
-    return this;
-  }
-
   public DeleteSchemaCommand setSchemaName(String schemaName) {
     _schemaName = schemaName;
     return this;
   }
 
-  public void setUser(String user) {
-    _user = user;
-  }
-
-  public void setPassword(String password) {
-    _password = password;
-  }
-
-  public void setAuthProvider(AuthProvider authProvider) {
-    _authProvider = authProvider;
-  }
-
-  public DeleteSchemaCommand setExecute(boolean exec) {
-    _exec = exec;
-    return this;
-  }
-
   @Override
   public boolean execute()
       throws Exception {
@@ -150,7 +74,7 @@ public class DeleteSchemaCommand extends 
AbstractBaseAdminCommand implements Com
     try (FileUploadDownloadClient fileUploadDownloadClient = new 
FileUploadDownloadClient()) {
       fileUploadDownloadClient.getHttpClient().sendDeleteRequest(
           FileUploadDownloadClient.getDeleteSchemaURI(_controllerProtocol, 
_controllerHost,
-              Integer.parseInt(_controllerPort), _schemaName), 
Collections.emptyMap(),
+              Integer.parseInt(_controllerPort), _schemaName), 
getHeadersAsMap(),
           AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, 
_authToken, _user, _password));
     } catch (Exception e) {
       LOGGER.error("Got Exception while deleting Pinot Schema: {}", 
_schemaName, e);
diff --git 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteTableCommand.java
 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteTableCommand.java
index cc31e20ab5..e6abc1842d 100644
--- 
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteTableCommand.java
+++ 
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/DeleteTableCommand.java
@@ -18,20 +18,17 @@
  */
 package org.apache.pinot.tools.admin.command;
 
-import java.util.Collections;
 import org.apache.pinot.common.auth.AuthProviderUtils;
 import org.apache.pinot.common.utils.FileUploadDownloadClient;
 import org.apache.pinot.spi.auth.AuthProvider;
-import org.apache.pinot.spi.utils.CommonConstants;
 import org.apache.pinot.spi.utils.NetUtils;
-import org.apache.pinot.tools.Command;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import picocli.CommandLine;
 
 
 @CommandLine.Command(name = "DeleteTable")
-public class DeleteTableCommand extends AbstractBaseAdminCommand implements 
Command {
+public class DeleteTableCommand extends AbstractDatabaseBaseAdminCommand {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(DeleteTableCommand.class);
 
   @CommandLine.Option(names = {"-tableName"}, required = true, description = 
"Name of the table to delete.")
@@ -45,43 +42,10 @@ public class DeleteTableCommand extends 
AbstractBaseAdminCommand implements Comm
       + "the cluster setting, then '7d'. Using 0d or -1d will instantly delete 
segments without retention.")
   private String _retention;
 
-  @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 = {"-exec"}, required = false, description = 
"Execute the command.")
-  private boolean _exec;
-
-  @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;
-
-  @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = 
false, help = true, description = "Print "
-      + "this message.")
-  private boolean _help = false;
-
   private String _controllerAddress;
 
   private AuthProvider _authProvider;
 
-  @Override
-  public boolean getHelp() {
-    return _help;
-  }
-
   @Override
   public String getName() {
     return "DeleteTable";
@@ -94,11 +58,8 @@ public class DeleteTableCommand extends 
AbstractBaseAdminCommand implements Comm
 
   @Override
   public String toString() {
-    String retString =
-        ("DeleteTable -tableName " + _tableName + " -type " + _type + " 
-retention " + _retention
-            + " -controllerProtocol " + _controllerProtocol + " 
-controllerHost " + _controllerHost
-            + " -controllerPort " + _controllerPort + " -user " + _user + " 
-password " + "[hidden]");
-    return ((_exec) ? (retString + " -exec") : retString);
+    return (getName() + " -tableName " + _tableName + " -type " + _type + " 
-retention " + _retention
+        + super.toString());
   }
 
   @Override
@@ -120,41 +81,6 @@ public class DeleteTableCommand extends 
AbstractBaseAdminCommand implements Comm
     return this;
   }
 
-  public DeleteTableCommand setControllerHost(String controllerHost) {
-    _controllerHost = controllerHost;
-    return this;
-  }
-
-  public DeleteTableCommand setControllerPort(String controllerPort) {
-    _controllerPort = controllerPort;
-    return this;
-  }
-
-  public DeleteTableCommand setControllerProtocol(String controllerProtocol) {
-    _controllerProtocol = controllerProtocol;
-    return this;
-  }
-
-  public DeleteTableCommand setUser(String user) {
-    _user = user;
-    return this;
-  }
-
-  public DeleteTableCommand setPassword(String password) {
-    _password = password;
-    return this;
-  }
-
-  public DeleteTableCommand setExecute(boolean exec) {
-    _exec = exec;
-    return this;
-  }
-
-  public DeleteTableCommand setAuthProvider(AuthProvider authProvider) {
-    _authProvider = authProvider;
-    return this;
-  }
-
   @Override
   public boolean execute()
       throws Exception {
@@ -170,10 +96,10 @@ public class DeleteTableCommand extends 
AbstractBaseAdminCommand implements Comm
 
     LOGGER.info("Executing command: {}", toString());
     try (FileUploadDownloadClient fileUploadDownloadClient = new 
FileUploadDownloadClient()) {
-      
fileUploadDownloadClient.getHttpClient().sendDeleteRequest(FileUploadDownloadClient
-          .getDeleteTableURI(_controllerProtocol, _controllerHost, 
Integer.parseInt(_controllerPort),
-              _tableName, _type, _retention), Collections.emptyMap(), 
AuthProviderUtils.makeAuthProvider(_authProvider,
-          _authTokenUrl, _authToken, _user, _password));
+      fileUploadDownloadClient.getHttpClient().sendDeleteRequest(
+          FileUploadDownloadClient.getDeleteTableURI(_controllerProtocol, 
_controllerHost,
+              Integer.parseInt(_controllerPort), _tableName, _type, 
_retention), getHeadersAsMap(),
+          AuthProviderUtils.makeAuthProvider(_authProvider, _authTokenUrl, 
_authToken, _user, _password));
     } catch (Exception e) {
       LOGGER.error("Got Exception while deleting Pinot Table: {}", _tableName, 
e);
       return false;


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

Reply via email to