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

[STORM-3616] add optional flag to fail upload-credentials cmd if no creds were uploaded #3243

Merged
merged 3 commits into from Apr 7, 2020

Conversation

RuiLi8080
Copy link
Contributor

@RuiLi8080 RuiLi8080 commented Apr 2, 2020

-bash-4.1$ storm upload-credentials ec2 -c "password=password"
Running: /home/y/share/yjava_jdk/java/bin/java -client -Ddaemon.name= -Dstorm.options=password%3Dpassword -Dstorm.home=/home/y/lib64/storm/2.2.0.y -Dstorm.log.dir=/home/y/lib64/storm/2.2.0.y/logs -Djava.library.path=/home/y/lib64:/usr/local/lib64:/usr/lib64:/lib64: -Dstorm.conf.file= -cp /home/y/lib64/storm/2.2.0.y/*:/home/y/lib64/storm/2.2.0.y/lib/*:/home/y/lib64/storm/2.2.0.y/extlib/*:/home/y/lib64/storm/2.2.0.y/extlib-daemon/*:/home/y/lib64/storm/current/conf:/home/y/lib64/storm/2.2.0.y/bin org.apache.storm.command.UploadCredentials ec2
03:31:54.653 [main] INFO o.a.s.m.n.Login - Successfully logged in to context StormClient using /etc/grid-keytabs/jaas.conf
03:31:54.662 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT refresh thread started.
03:31:54.691 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT valid starting at: Wed Apr 01 05:14:11 UTC 2020
03:31:54.691 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT expires: Thu Apr 02 05:14:11 UTC 2020
03:31:54.691 [Refresh-TGT] WARN o.a.s.m.n.Login - TGT refresh thread time adjusted from : Thu Apr 02 01:30:31 UTC 2020 to : Thu Apr 02 03:32:54 UTC 2020 since the former is sooner than the minimum refresh interval (60 seconds) from now.
03:31:54.692 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT refresh sleeping until: Thu Apr 02 03:32:54 UTC 2020
03:31:54.835 [main] INFO o.a.s.u.NimbusClient - Found leader nimbus : openstorm13blue-n1.blue.ygrid.yahoo.com:50560
03:31:54.897 [main] INFO o.a.s.c.UploadCredentials - Using topology conf from ec2-1-1585797718 as basis for getting new creds
03:31:54.924 [main] INFO o.a.s.s.a.ClientAuthUtils - Got AutoCreds []
03:31:54.924 [main] INFO o.a.s.StormSubmitter - Full list of creds available: {}
03:31:54.924 [main] WARN o.a.s.StormSubmitter - No credentials were found to push to ec2
03:31:54.924 [main] INFO o.a.s.c.UploadCredentials - Uploaded new creds to topology: ec2
-bash-4.1$ echo $?
0

 

-bash-4.1$ storm upload-credentials ec2 -c "password=password" -e

Running: /home/y/share/yjava_jdk/java/bin/java -client -Ddaemon.name= -Dstorm.options=password%3Dpassword -Dstorm.home=/home/y/lib64/storm/2.2.0.y -Dstorm.log.dir=/home/y/lib64/storm/2.2.0.y/logs -Djava.library.path=/home/y/lib64:/usr/local/lib64:/usr/lib64:/lib64: -Dstorm.conf.file= -cp /home/y/lib64/storm/2.2.0.y/*:/home/y/lib64/storm/2.2.0.y/lib/*:/home/y/lib64/storm/2.2.0.y/extlib/*:/home/y/lib64/storm/2.2.0.y/extlib-daemon/*:/home/y/lib64/storm/current/conf:/home/y/lib64/storm/2.2.0.y/bin org.apache.storm.command.UploadCredentials ec2 -e
03:32:30.449 [main] INFO o.a.s.m.n.Login - Successfully logged in to context StormClient using /etc/grid-keytabs/jaas.conf
03:32:30.471 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT refresh thread started.
03:32:30.492 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT valid starting at: Wed Apr 01 05:14:11 UTC 2020
03:32:30.493 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT expires: Thu Apr 02 05:14:11 UTC 2020
03:32:30.493 [Refresh-TGT] WARN o.a.s.m.n.Login - TGT refresh thread time adjusted from : Thu Apr 02 01:25:36 UTC 2020 to : Thu Apr 02 03:33:30 UTC 2020 since the former is sooner than the minimum refresh interval (60 seconds) from now.
03:32:30.493 [Refresh-TGT] INFO o.a.s.m.n.Login - TGT refresh sleeping until: Thu Apr 02 03:33:30 UTC 2020
03:32:30.641 [main] INFO o.a.s.u.NimbusClient - Found leader nimbus : openstorm13blue-n1.blue.ygrid.yahoo.com:50560
03:32:30.702 [main] INFO o.a.s.c.UploadCredentials - Using topology conf from ec2-1-1585797718 as basis for getting new creds
03:32:30.729 [main] INFO o.a.s.s.a.ClientAuthUtils - Got AutoCreds []
03:32:30.729 [main] INFO o.a.s.StormSubmitter - Full list of creds available: {}
03:32:30.729 [main] WARN o.a.s.StormSubmitter - No credentials were found to push to ec2
03:32:30.730 [main] ERROR o.a.s.c.UploadCredentials - No credentials were uploaded for ec2

Exception in thread "main" java.lang.RuntimeException: No credentials were uploaded for ec2
     at org.apache.storm.command.UploadCredentials.main(UploadCredentials.java:120)

-bash-4.1$ echo $?
1

@@ -319,7 +319,9 @@ eg: `storm shell resources/ python topology.py arg1 arg2`

Syntax: `storm upload_credentials topology-name [credkey credvalue]*`

Uploads a new set of credentials to a running topology
Uploads a new set of credentials to a running topology
* `-e --exception`: optioanl flag. If set, command will fail and throw exception if no credentials were uploaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

type "optioanl"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

bin/storm.py Outdated
# If set, this flag will become true meaning that user expects non-empty creds to be uploaded.
# Command exits with non-zero code if uploaded creds collection is empty.
sub_parser.add_argument(
"-e", "--exception", action='store_true',
Copy link
Contributor

Choose a reason for hiding this comment

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

--exception is too general. Maybe --fail-on-empty or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed --exception-when-empty here since we already use short name -f for file.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is also good

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is args.exception_when_empty passed to java command (in storm.py:upload_credentials()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems there is a slight problem. In python code, when exec_java_class() is called, the arguments to the java class is constructed partly from main_class_args. main_class_args is constructed by simply eliminating some arguments passed to the python code (and keeping the rest intact). So if python code got passed "-e" ii will get passed thru to java class as "-e". However, if "--exception was passed to python, then --exception will get passed to java. This wont match what java class is expecting. So in order to do a passthru, the option names should be the same, otherwise main_class_args should be suitably modified based on the args. Looks like passthru might be preferred solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, the argument in python is the same: "--exception-when-empty".

@@ -126,7 +127,7 @@ public static void pushCredentials(String name, Map<String, Object> topoConf, Ma
* @throws NotAliveException if the topology is not alive
* @throws InvalidTopologyException if any other error happens
*/
public static void pushCredentials(String name, Map<String, Object> topoConf, Map<String, String> credentials, String expectedUser)
public static boolean pushCredentials(String name, Map<String, Object> topoConf, Map<String, String> credentials, String expectedUser)
Copy link
Contributor

Choose a reason for hiding this comment

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

missing javadoc @return

There is another pushCredentials method in this class needs to be taken care of

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -111,7 +112,13 @@ public static void main(String[] args) throws Exception {
// use the local setting for the login config rather than the topology's
topologyConf.remove("java.security.auth.login.config");

StormSubmitter.pushCredentials(topologyName, topologyConf, credentialsMap, (String) cl.get("u"));
boolean throwExceptionForEmptyCreds = (boolean) cl.getOrDefault("e", false);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for default value here. above boolOpt is already default to false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -319,7 +319,9 @@ eg: `storm shell resources/ python topology.py arg1 arg2`

Syntax: `storm upload_credentials topology-name [credkey credvalue]*`

Uploads a new set of credentials to a running topology
Uploads a new set of credentials to a running topology
* `-e --exception`: optional flag. If set, command will fail and throw exception if no credentials were uploaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be updated too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed

bin/storm.py Outdated
# Command exits with non-zero code if uploaded creds collection is empty.
sub_parser.add_argument(
"-e", "--exception-when-empty", action='store_true',
help="""whether to throw exception if there are no credentials uploaded, default to be false"""
Copy link
Contributor

Choose a reason for hiding this comment

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

It means true when this config is specified, otherwise it's false.

So more precisely, "If specified, throws an exception if no credentials are uploaded"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -106,27 +106,30 @@ public static boolean validateZKDigestPayload(String payload) {
* @param name the name of the topology to push credentials to.
* @param topoConf the topology-specific configuration, if desired. See {@link Config}.
* @param credentials the credentials to push.
* @return whether the pushed credential collection fullCreds is non-empty. Return false if empty.
Copy link
Contributor

@Ethanlm Ethanlm Apr 2, 2020

Choose a reason for hiding this comment

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

fullCreds doesn't really mean anything and can be deleted; image anyone changed the variable name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only one Travis build failed. Should be irrelevant.

Copy link
Contributor

@Ethanlm Ethanlm left a comment

Choose a reason for hiding this comment

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

+1

@Ethanlm Ethanlm merged commit b38e159 into apache:master Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants