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

[broker] change getWorkerService method to throw UnsupportedOperationException #9738

Merged
merged 3 commits into from
Mar 3, 2021

Conversation

golden-yang
Copy link
Contributor

Fix #9633

Motivation

When we set functionsWorkerEnabled=false in broker.conf, broker don't support management function of functionWorker.
But when we try to appy those method. Broker will throw NullPointerException instead of throwing a more user friendly error that explain the problem.

This PR is trying to fix it.

Modifications

  • Throw an exception instead of returning null
  • Add unit test for normal and abnormal conditions

Documentation

  • Does this pull request introduce a new feature? ( no)

Comment on lines 960 to 962
public WorkerService getWorkerService() throws UnsupportedOperationException {
return functionWorkerService.orElseThrow(() -> new UnsupportedOperationException("Pulsar Function Worker is not " +
"enabled, probably functionsWorkerEnabled is set to false"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use getWorkerServiceOpt() to check if the workerService is present? Since the workerService might be used in multiple places if we throw an exception here, this means all the places will throw an exception, this is not necessarily the right choice for all operations. So my suggestion is to let the caller to decide the behavior by checking the getWorkerServiceOpt().

Copy link
Contributor

Choose a reason for hiding this comment

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

And please check the failed tests, there are 2 Checkstyle violations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before submitting the code, I forgot to check the code style. I have already checked and resubmitted
thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using getWorkerServiceOpt directly may be a more elegant implementation, but it will change too many places, and the expected behavior of most methods is also to throw a clearer exception.
In your opinion, which one is better?
Simplify the implementation or use a more elegant return value.
Maybe you have a better idea, Thank you again for your advice

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, If throw exception while getWorkerService(), this might break some other places since it might just want to return a null value. As I said before if all the places are ok for handling the exception that getWorkerService() throws, I'm ok. I just worry about introducing some break changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@codelipenghui I share your opinion.
but if all of the tests are passing, especially integration tests, we should be safe.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@codelipenghui Thank you for your suggestion. I understand your consideration.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@codelipenghui codelipenghui merged commit baceabd into apache:master Mar 3, 2021
mlyahmed pushed a commit to mlyahmed/pulsar that referenced this pull request Mar 5, 2021
…Exception (apache#9738)

Fix apache#9633 

### Motivation
When we set `functionsWorkerEnabled=false` in `broker.conf`, broker don't support management function of `functionWorker`.
But when we try to appy those method. Broker will throw NullPointerException  instead of throwing a more user friendly error that explain the problem.
codelipenghui pushed a commit that referenced this pull request Jun 26, 2021
…Exception (#9738)

Fix #9633

When we set `functionsWorkerEnabled=false` in `broker.conf`, broker don't support management function of `functionWorker`.
But when we try to appy those method. Broker will throw NullPointerException  instead of throwing a more user friendly error that explain the problem.

(cherry picked from commit baceabd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pulsar Admin: functions - NullPointerException in case of disabled Pulsar Functions
3 participants