Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#770] feat(cli): Introduce apache.commons.cli basic framework #833

Merged
merged 11 commits into from
Apr 27, 2023

Conversation

slfan1989
Copy link
Collaborator

@slfan1989 slfan1989 commented Apr 20, 2023

What changes were proposed in this pull request?

We use apache.commons.cli to add commands to Uniffle. I created a command called uniffle, the following is the case of using the command.

Case1: Use the uniffle command directly.

  • uniffle / uniffle --help
Usage: uniffle [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS]
 or    uniffle [OPTIONS] CLASSNAME [CLASSNAME OPTIONS]
  where CLASSNAME is a user-provided Java class

  OPTIONS is none or any of:

--daemon (start|status|stop)   operate on a daemon

  SUBCOMMAND is one of:


    Admin Commands:

admin-cli    prints uniffle-admin args information

    Client Commands:

client-cli   prints uniffle-cli args information

SUBCOMMAND may print help when invoked w/o parameters or with -h.

Case2: use a command that does not create.

  • uniffle testadmin
ERROR: testadmin is not COMMAND nor fully qualified CLASSNAME.
DEBUG: UNIFFLE_SUBCMD_USAGE_TYPES accepted client
DEBUG: UNIFFLE_SUBCMD_USAGE_TYPES accepted admin
Usage: uniffle [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS]
 or    uniffle [OPTIONS] CLASSNAME [CLASSNAME OPTIONS]
  where CLASSNAME is a user-provided Java class

  OPTIONS is none or any of:

--daemon (start|status|stop)   operate on a daemon

  SUBCOMMAND is one of:


    Admin Commands:

admin-cli    prints uniffle-admin args information

    Client Commands:

client-cli   prints uniffle-cli args information

SUBCOMMAND may print help when invoked w/o parameters or with -h.

Case3: Use the help command

  • uniffle client-cli --help
Usage:
   Optional
     -a,--admin <arg>   This is an admin command that will print args.
     -c,--cli <arg>     This is an client cli command that will print args.
     -h,--help          Help for the Uniffle CLI.

Case4: Run the example-cli command

  • uniffle client-cli --cli test-cli
uniffle-client-cli : test-cli

Why are the changes needed?

We use apache.commons.cli to add commands to Uniffle.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Unit test verification.
  • Execute commands directly.

@slfan1989 slfan1989 marked this pull request as draft April 20, 2023 12:42
@slfan1989
Copy link
Collaborator Author

slfan1989 commented Apr 20, 2023

@smallzhongfeng @jerqi Can you help to review this pr? Thank you very much!

@codecov-commenter
Copy link

codecov-commenter commented Apr 21, 2023

Codecov Report

Merging #833 (b5406c1) into master (47c4966) will increase coverage by 2.22%.
The diff coverage is 54.16%.

@@             Coverage Diff              @@
##             master     #833      +/-   ##
============================================
+ Coverage     57.09%   59.32%   +2.22%     
- Complexity     2148     2165      +17     
============================================
  Files           321      305      -16     
  Lines         15655    13388    -2267     
  Branches       1243     1249       +6     
============================================
- Hits           8939     7943     -996     
+ Misses         6212     5009    -1203     
+ Partials        504      436      -68     
Impacted Files Coverage Δ
...va/org/apache/uniffle/UniffleCliArgsException.java 0.00% <0.00%> (ø)
.../org/apache/uniffle/AbstractCustomCommandLine.java 54.83% <54.83%> (ø)
...c/main/java/org/apache/uniffle/cli/UniffleCLI.java 59.45% <59.45%> (ø)

... and 25 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@slfan1989 slfan1989 marked this pull request as ready for review April 21, 2023 10:40
bin/uniffle-function.sh Show resolved Hide resolved
bin/uniffle-function.sh Outdated Show resolved Hide resolved
bin/utils.sh Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
@@ -21,6 +21,7 @@ set -o pipefail
set -o nounset # exit the script if you try to use an uninitialised variable
set -o errexit # exit the script if any statement returns a non-true return value

UNIFFLE_SHELL_SCRIPT_DEBUG=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we put UNIFFLE_SHELL_SCRIPT_DEBUG=true into utils.sh and load_rss_env?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will modify the code.

function uniffle_generic_java_subcmd_handler
{
uniffle_java_exec "${UNIFFLE_SUBCMD}" "${UNIFFLE_CLASSNAME}" "${UNIFFLE_SUBCMD_ARGS[@]}"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line. There is a warning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping to review the code, I will fix it.

@jerqi
Copy link
Contributor

jerqi commented Apr 21, 2023

cc @Kwafoor

import org.apache.uniffle.UniffleCliArgsException;


public class ExampleCLI extends AbstractCustomCommandLine {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a better name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about UniffleTestCLI?

Copy link
Contributor

@jerqi jerqi Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need an ExampleCli? Coulw we have a UniffleCli directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need an ExampleCli? Coulw we have a UniffleCli directly?

Thank you for your suggestion! I will modify the class name, and I will continue to complete subTask in this class, #837, #846.

My idea is to provide a sample class for testing, so it is called exampleCLI, but it is called uniffleCLI, which is a better choice.

bin/uniffle Outdated
set +u
uniffle_cmd_case "${UNIFFLE_SUBCMD}" "${UNIFFLE_SUBCMD_ARGS[@]}"
uniffle_generic_java_subcmd_handler
set -u
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a new line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it.

cli/pom.xml Outdated
<artifactId>commons-cli</artifactId>
</dependency>
</dependencies>
</project>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a new line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it.

@jerqi
Copy link
Contributor

jerqi commented Apr 27, 2023

Refer to Yarn, should we have ClientCli and AdminCli? Both of them extend the UniffeCli?
企业微信截图_80f351ae-b099-4aac-94ba-8505741b0c14

@slfan1989
Copy link
Collaborator Author

slfan1989 commented Apr 27, 2023

Refer to Yarn, should we have ClientCli and AdminCli? Both of them extend the UniffeCli?

@jerqi

Thank you for your question! In the case of YARN, there are clear distinctions between client and admin operations, so it makes sense to separate them using different CLIs. This can help improve usability of the tool.

In general, I believe that Uniffle should differentiate between two sets of commands for clients and admins.

At present, there are only a few known commands for Uniffle. I suggest that we could develop them within UniffleCLI and use options to differentiate between them. If necessary, we can always consider splitting them into separate client and admin CLIs later on.

Do you think this approach would be feasible?

@jerqi
Copy link
Contributor

jerqi commented Apr 27, 2023

Refer to Yarn, should we have ClientCli and AdminCli? Both of them extend the UniffeCli?

Thank you for your question! In the case of YARN, there are clear distinctions between client and admin operations, so it makes sense to separate them using different CLIs. This can help improve usability of the tool.

In general, I believe that Uniffle should differentiate between two sets of commands for clients and admins.

At present, there are only a few known commands for Uniffle. I suggest that we could develop them within UniffleCLI and use options to differentiate between them. If necessary, we can always consider splitting them into separate client and admin CLIs later on.

Do you think this approach would be feasible?

I'm ok.

smallzhongfeng
smallzhongfeng previously approved these changes Apr 27, 2023
Copy link
Contributor

@smallzhongfeng smallzhongfeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. also cc @jerqi After merging this PR, we can start developing some other commands.

jerqi
jerqi previously approved these changes Apr 27, 2023
Copy link
Contributor

@jerqi jerqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jerqi
Copy link
Contributor

jerqi commented Apr 27, 2023

What changes were proposed in this pull request?

We use apache.commons.cli to add commands to Uniffle. I created a command called uniffle, the following is the case of using the command.

Case1: Use the uniffle command directly.

  • uniffle / uniffle --help
Usage: uniffle [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS]
 or    uniffle [OPTIONS] CLASSNAME [CLASSNAME OPTIONS]
  where CLASSNAME is a user-provided Java class

  OPTIONS is none or any of:

--daemon (start|status|stop)   operate on a daemon

  SUBCOMMAND is one of:

    Admin Commands:

example-admin   prints example-admin args information

    Client Commands:

example-cli     prints example-cli args information

SUBCOMMAND may print help when invoked w/o parameters or with -h.

Case2: use a command that does not create.

  • uniffle testadmin.
ERROR: testadmin is not COMMAND nor fully qualified CLASSNAME.
DEBUG: UNIFFLE_SUBCMD_USAGE_TYPES accepted client
DEBUG: UNIFFLE_SUBCMD_USAGE_TYPES accepted admin
Usage: uniffle [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS]
 or    uniffle [OPTIONS] CLASSNAME [CLASSNAME OPTIONS]
  where CLASSNAME is a user-provided Java class

  OPTIONS is none or any of:

--daemon (start|status|stop)   operate on a daemon

  SUBCOMMAND is one of:

    Admin Commands:

example-admin   prints example-admin args information

    Client Commands:

example-cli     prints example-cli args information

SUBCOMMAND may print help when invoked w/o parameters or with -h.

Case3: Use the help command

  • uniffle example-cli --help
Usage:
   Optional
     -a,--admin <arg>   This is an example admin command that will print args.
     -c,--cli <arg>     This is an example cli command that will print args.
     -h,--help          Help for the Uniffle Example-CLI.

Case4: Run the example-cli command

  • uniffle example-cli --cli test-cli
example-cli : test-cli

Why are the changes needed?

We use apache.commons.cli to add commands to Uniffle.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Unit test verification.
  • Execute commands directly.

Do we need modify the description? Is there some update?

@slfan1989 slfan1989 dismissed stale reviews from jerqi and smallzhongfeng via 2fe59ff April 27, 2023 07:53
@jerqi jerqi changed the title [#770] Introduce apache.commons.cli basic framework [#770] feat(cli): Introduce apache.commons.cli basic framework Apr 27, 2023
@jerqi jerqi requested a review from kaijchen April 27, 2023 08:51
@jerqi
Copy link
Contributor

jerqi commented Apr 27, 2023

@kaijchen Do you have another suggestion? You have more experience about Ratis and Ozone client. If you have another suggestion, you can raise some follow-up prs.
I prefer merging this pr first when it passed CI. It will be convenient for us.Many issues will rely on this pr.

Copy link
Contributor

@jerqi jerqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged. Thanks all

@jerqi jerqi merged commit a3ca258 into apache:master Apr 27, 2023
@slfan1989
Copy link
Collaborator Author

@jerqi @smallzhongfeng Thank you very much for reviewing the code and providing suggestions for modification!

@jerqi
Copy link
Contributor

jerqi commented Apr 27, 2023

Do you have Wechat acount? Have you joined Uniffle Wechat Group? If you want to join our group, you can scan
Screenshot_2023-04-27-19-23-30-802_com tencent mm

@smallzhongfeng smallzhongfeng changed the title [#770] feat(cli): Introduce apache.commons.cli basic framework [#758] feat(cli): Introduce apache.commons.cli basic framework May 6, 2023
@smallzhongfeng smallzhongfeng changed the title [#758] feat(cli): Introduce apache.commons.cli basic framework [#770] feat(cli): Introduce apache.commons.cli basic framework May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants