You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by "advancedxy (via GitHub)" <gi...@apache.org> on 2023/07/19 06:28:20 UTC

[GitHub] [incubator-uniffle] advancedxy commented on a diff in pull request #964: [#837] feat: Display information of all application through Cli.

advancedxy commented on code in PR #964:
URL: https://github.com/apache/incubator-uniffle/pull/964#discussion_r1267581078


##########
cli/src/main/java/org/apache/uniffle/cli/UniffleAdminCLI.java:
##########
@@ -52,24 +48,8 @@ public UniffleAdminCLI(String shortPrefix, String longPrefix) {
     help =
         new Option(
             shortPrefix + "h", longPrefix + "help", false, "Help for the Uniffle Admin CLI.");
-    coordinatorHost =
-        new Option(
-            shortPrefix + "s",
-            longPrefix + "coordinatorHost",
-            true,
-            "This is coordinator server host.");
-    coordinatorPort =
-        new Option(
-            shortPrefix + "p",
-            longPrefix + "coordinatorPort",
-            true,
-            "This is coordinator server port.");
-    ssl = new Option(null, longPrefix + "ssl", false, "use SSL.");

Review Comment:
   Previous there's no -s (short option) for --ssl, do you think we should maintain this behavior?



##########
cli/src/main/java/org/apache/uniffle/cli/UniffleCLI.java:
##########
@@ -48,15 +66,41 @@ public UniffleCLI(String shortPrefix, String longPrefix) {
             longPrefix + "admin",
             true,
             "This is an admin command that will print args.");
+    uniffleApplicationCli =
+        new Option(
+            shortPrefix + "apps",
+            longPrefix + "applications",
+            true,
+            "The command will be used to print a list of applications. \n"
+                + "We usually use the command like this: \n"
+                + "uniffle -apps|--applications application_167671938823_0001,application_167671938823_0002");
+    uniffleOutPutJson =
+        new Option(
+            shortPrefix + "o",
+            longPrefix + "output-json",

Review Comment:
   In my experience, we normally construct this options as  `-o json | --output-format json`. It's possible to output other format of data, such as yaml, xml etc. However they are less popular, and would probably never been implemented.



##########
cli/src/main/java/org/apache/uniffle/cli/UniffleCLI.java:
##########
@@ -48,15 +66,41 @@ public UniffleCLI(String shortPrefix, String longPrefix) {
             longPrefix + "admin",
             true,
             "This is an admin command that will print args.");
+    uniffleApplicationCli =
+        new Option(
+            shortPrefix + "apps",
+            longPrefix + "applications",

Review Comment:
   `-apps` doesn't seem short. How about make this option an alias of applications? a.k.a `--apps | --applications`.
   They are both long options.



##########
coordinator/src/main/java/org/apache/uniffle/coordinator/web/resource/ServerResource.java:
##########
@@ -121,7 +126,29 @@ public Response<Object> decommission(@PathParam("id") String serverId) {
         });
   }
 
+  @POST

Review Comment:
   Per REST principle, I think we should use `GET` instead of `POST`?



##########
coordinator/src/main/java/org/apache/uniffle/coordinator/web/resource/ServerResource.java:
##########
@@ -121,7 +126,29 @@ public Response<Object> decommission(@PathParam("id") String serverId) {
         });
   }
 
+  @POST

Review Comment:
   And would you mind to add a UT for this route?



##########
cli/src/main/java/org/apache/uniffle/cli/UniffleCLI.java:
##########
@@ -48,15 +66,41 @@ public UniffleCLI(String shortPrefix, String longPrefix) {
             longPrefix + "admin",
             true,
             "This is an admin command that will print args.");
+    uniffleApplicationCli =
+        new Option(
+            shortPrefix + "apps",
+            longPrefix + "applications",

Review Comment:
   And it sems like there's no way to list all applications?



##########
cli/src/main/java/org/apache/uniffle/cli/UniffleCLI.java:
##########
@@ -74,20 +118,107 @@ public int run(String[] args) throws UniffleCliArgsException {
       return 0;
     }
 
+    if (cmd.hasOption(coordinatorHost.getOpt()) && cmd.hasOption(coordinatorPort.getOpt())) {
+      getUniffleRestClient(cmd);
+    }
+
+    // If we use application-cli
+    if (cmd.hasOption(uniffleApplicationCli.getOpt())) {
+      LOG.info("uniffle-client-cli : get applications");
+      // If we want to output json file
+      if (cmd.hasOption(uniffleOutPutJson.getOpt())) {

Review Comment:
   I was thinking the json is also printed to stdout if specified.
   It's either formatted output or json output, otherwise it maybe a little inconvenient to third-party tools to handle the output of this tool.
    



##########
cli/src/main/java/org/apache/uniffle/cli/UniffleCLI.java:
##########
@@ -74,20 +118,107 @@ public int run(String[] args) throws UniffleCliArgsException {
       return 0;
     }
 
+    if (cmd.hasOption(coordinatorHost.getOpt()) && cmd.hasOption(coordinatorPort.getOpt())) {
+      getUniffleRestClient(cmd);
+    }
+
+    // If we use application-cli
+    if (cmd.hasOption(uniffleApplicationCli.getOpt())) {
+      LOG.info("uniffle-client-cli : get applications");
+      // If we want to output json file
+      if (cmd.hasOption(uniffleOutPutJson.getOpt())) {
+        String outPutPath = cmd.getOptionValue(uniffleOutPutJson.getOpt()).trim();
+        String json = getApplicationsJson(cmd);
+        try (FileOutputStream fos = new FileOutputStream(outPutPath);
+            OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
+          osw.write(json);
+          System.out.println(
+              "applications json data has been written to the file(" + outPutPath + ").");
+        } catch (IOException e) {
+          System.out.println(
+              "An error occurred while writing the applications json data to the file("
+                  + outPutPath
+                  + ").");
+        }
+      }
+      try (PrintWriter writer =
+          new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8))) {
+        FormattingCLIUtils formattingCLIUtils =
+            new FormattingCLIUtils("Uniflle Applications").addHeaders(APPLICATIONS_HEADER);
+        List<Application> applications = getApplications(cmd);
+        if (applications != null) {
+          applications.forEach(
+              app ->
+                  formattingCLIUtils.addLine(
+                      app.getApplicationId(),
+                      app.getUser(),
+                      app.getLastHeartBeatTime(),
+                      app.getRemoteStoragePath()));
+        }
+        writer.print(formattingCLIUtils.render());
+        writer.flush();

Review Comment:
   nit: maybe we need to support paging and stream write if there are many apps, for example 10_000 apps.
   
   However let's track that in follow up prs.



-- 
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: issues-unsubscribe@uniffle.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org