acelyc111 commented on code in PR #1471:
URL: 
https://github.com/apache/incubator-pegasus/pull/1471#discussion_r1193379924


##########
java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClientInterface.java:
##########
@@ -71,6 +73,16 @@ public void createApp(
 
   public void dropApp(String appName, int reserveSeconds) throws PException;
 
+  /**
+   * Get all app names of the pegasus cluster
+   *
+   * @param onlyGetAvailableApps Whether to return all available tables, true 
means to return only
+   *     available tables, false means to return all tables, including dropped 
tables

Review Comment:
   ```suggestion
      *     available tables, false means to return all tables, including 
dropped but currently reserved tables
   ```



##########
java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClientInterface.java:
##########
@@ -71,6 +73,16 @@ public void createApp(
 
   public void dropApp(String appName, int reserveSeconds) throws PException;
 
+  /**
+   * Get all app names of the pegasus cluster
+   *
+   * @param onlyGetAvailableApps Whether to return all available tables, true 
means to return only
+   *     available tables, false means to return all tables, including dropped 
tables
+   * @param appInfoList List of all table names in the pegasus cluster

Review Comment:
   Not only "table names" are listed, the `app_info` all fields are listed?



##########
java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java:
##########
@@ -230,4 +232,34 @@ public void dropApp(String appName, int reserveSeconds) 
throws PException {
           String.format("Drop app:%s failed! error: %s.", appName, 
error.toString()));
     }
   }
+
+  @Override
+  public void listApps(boolean onlyGetAvailableApps, List<app_info> 
appInfoList) throws PException {
+    if (!appInfoList.isEmpty()) {
+      throw new PException(
+          new IllegalArgumentException(
+              String.format("listApps failed: output parameters 'appInfoList' 
not empty.")));

Review Comment:
   ```suggestion
                 String.format("listApps failed: output parameters 
'appInfoList' not empty.")));
   ```
   ```suggestion
                 String.format("listApps failed: output parameters 
'appInfoList' is not empty.")));
   ```



##########
java-client/src/test/java/org/apache/pegasus/client/TestAdminClient.java:
##########
@@ -134,4 +137,35 @@ public void testDropApp() throws PException {
     pClient.close();
     Assert.fail("expected PException for openTable");
   }
+
+  @Test
+  public void testListApps() throws PException {
+    String appName = "testListApps" + System.currentTimeMillis();
+    List<app_info> appInfoList = new ArrayList<>();
+    toolsClient.listApps(true, appInfoList);

Review Comment:
   Do you suppose there are all "available" tables in the cluster?



##########
java-client/src/test/java/org/apache/pegasus/client/TestAdminClient.java:
##########
@@ -134,4 +137,35 @@ public void testDropApp() throws PException {
     pClient.close();
     Assert.fail("expected PException for openTable");
   }
+
+  @Test
+  public void testListApps() throws PException {
+    String appName = "testListApps" + System.currentTimeMillis();
+    List<app_info> appInfoList = new ArrayList<>();
+    toolsClient.listApps(true, appInfoList);
+    int size1 = appInfoList.size();
+    toolsClient.createApp(
+        appName,
+        this.tablePartitionCount,
+        this.tableReplicaCount,
+        new HashMap<>(),
+        this.tableOpTimeoutMs);
+    boolean isAppHealthy = toolsClient.isAppHealthy(appName, 
this.tableReplicaCount);
+    Assert.assertTrue(isAppHealthy);
+
+    appInfoList.clear();
+    toolsClient.listApps(true, appInfoList);
+    Assert.assertTrue(appInfoList.size() == size1 + 1);

Review Comment:
   Use assertEquals instead?



##########
java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java:
##########
@@ -230,4 +232,34 @@ public void dropApp(String appName, int reserveSeconds) 
throws PException {
           String.format("Drop app:%s failed! error: %s.", appName, 
error.toString()));
     }
   }
+
+  @Override
+  public void listApps(boolean onlyGetAvailableApps, List<app_info> 
appInfoList) throws PException {

Review Comment:
   How about use an enum instead of bool? 
   
   
https://betterprogramming.pub/dont-use-boolean-arguments-use-enums-c7cd7ab1876a



##########
java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java:
##########
@@ -230,4 +232,34 @@ public void dropApp(String appName, int reserveSeconds) 
throws PException {
           String.format("Drop app:%s failed! error: %s.", appName, 
error.toString()));
     }
   }
+
+  @Override
+  public void listApps(boolean onlyGetAvailableApps, List<app_info> 
appInfoList) throws PException {
+    if (!appInfoList.isEmpty()) {
+      throw new PException(
+          new IllegalArgumentException(
+              String.format("listApps failed: output parameters 'appInfoList' 
not empty.")));
+    }
+
+    configuration_list_apps_request request = new 
configuration_list_apps_request();
+    request.setStatus(app_status.AS_AVAILABLE);
+    if (!onlyGetAvailableApps) {
+      request.setStatus(app_status.AS_INVALID);
+    }
+
+    list_apps_operator app_operator = new list_apps_operator(request);
+    error_code.error_types error = this.meta.operate(app_operator, 
META_RETRY_MIN_COUNT);
+
+    if (error != error_code.error_types.ERR_OK) {
+      throw new PException(
+          String.format(
+              "List apps failed, query status:%s, error:%s.",
+              request.getStatus(), error.toString()));
+    }
+
+    configuration_list_apps_response response = app_operator.get_response();
+    for (int i = 0; i < response.infos.size(); i++) {

Review Comment:
   The type of `response.infos` is ArrayList, why not directly assign it to 
`appInfoList`?



##########
java-client/src/main/java/org/apache/pegasus/operator/list_apps_operator.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.pegasus.operator;
+
+import org.apache.pegasus.base.gpid;
+import org.apache.pegasus.replication.admin_client.list_apps_args;
+import org.apache.pegasus.replication.admin_client.list_apps_result;
+import org.apache.pegasus.replication.configuration_list_apps_request;
+import org.apache.pegasus.replication.configuration_list_apps_response;
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TMessage;
+import org.apache.thrift.protocol.TMessageType;
+import org.apache.thrift.protocol.TProtocol;
+
+public class list_apps_operator extends client_operator {
+  public list_apps_operator(configuration_list_apps_request request) {
+    super(new gpid(), "", 0);
+    this.request = request;
+  }
+
+  @Override
+  public String name() {
+    return "list_apps_operator";
+  }
+
+  @Override
+  public void send_data(TProtocol oprot, int sequence_id) throws TException {
+    TMessage msg = new TMessage("RPC_CM_LIST_APPS", TMessageType.CALL, 
sequence_id);
+    oprot.writeMessageBegin(msg);
+    org.apache.pegasus.replication.admin_client.list_apps_args args = new 
list_apps_args(request);

Review Comment:
   Can the prefix `org.apache.pegasus.replication.admin_client.` be omitted?



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

To unsubscribe, e-mail: [email protected]

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


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

Reply via email to