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

Implement TaskServlet::doGet to list tasks lexically. #1939

Merged
merged 2 commits into from Feb 27, 2017

Conversation

aaanders
Copy link

Tasks are logged on startup but aren't easily accessible otherwise. Implement TaskServlet::doGet to print tasks lexically by name.

Example:

$ curl http://localhost:8081/tasks
echo
gc
log-level

TaskServlet is mapped on "/tasks/*" and any GET request not matching root
will yield 404 or 405.

404: Task name is unknown.
405: Task name is registered but must be invoked with POST.

Implement doGet in TaskServlet in order to be able to query registered
tasks.
Returns the registered tasks ordered lexically by Task::getName.

Since TaskServlet matches "/tasks/*" any GET request not matching root will
yield 404 or 405.

404:
Task name is unknown.
405:
Task name is registered but must be invoked with POST.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 84.899% when pulling 75a93cd on aaanders:list-tasks into e823137 on dropwizard:master.

@aaanders aaanders mentioned this pull request Feb 27, 2017
@aaanders aaanders closed this Feb 27, 2017
@aaanders aaanders reopened this Feb 27, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 84.905% when pulling 75a93cd on aaanders:list-tasks into e823137 on dropwizard:master.

if (Strings.isNullOrEmpty(req.getPathInfo())) {
try (final PrintWriter output = resp.getWriter()) {
resp.setContentType(MediaType.PLAIN_TEXT_UTF_8.toString());
final ArrayList<Task> tasks = new ArrayList<>(getTasks());
Copy link
Member

Choose a reason for hiding this comment

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

This (and the following lines) could be replaced by:

getTasks().stream()
    .map(Task::getName)
    .sorted()
    .forEach(output::println);

Copy link
Author

Choose a reason for hiding this comment

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

Nice, thanks @joschi, nice and clean. (Grepping for stream() made me think it was a bad idea to use it :D )

@joschi joschi self-assigned this Feb 27, 2017
@joschi joschi added this to the 1.1.0 milestone Feb 27, 2017
import com.google.common.collect.ImmutableMultimap;
import com.google.common.io.CharStreams;
import com.google.common.net.MediaType;
import java.util.ArrayList;
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the unused imports. Then we're good to go.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

* Use stream()  when looping, sorting and printing task names.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.807% when pulling 4c2659a on aaanders:list-tasks into 5ece507 on dropwizard:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.807% when pulling 4c2659a on aaanders:list-tasks into 5ece507 on dropwizard:master.

@joschi joschi merged commit e94deb2 into dropwizard:master Feb 27, 2017
joschi pushed a commit that referenced this pull request Feb 27, 2017
Implement doGet in TaskServlet in order to be able to query registered
tasks.
Returns the registered tasks ordered lexically by Task::getName.

Since TaskServlet matches "/tasks/*" any GET request not matching root will
yield 404 or 405.

404:
Task name is unknown.
405:
Task name is registered but must be invoked with POST.

Closes #1940
(cherry picked from commit e94deb2)
@aaanders
Copy link
Author

Thanks for reviewing @joschi

@aaanders aaanders deleted the list-tasks branch February 27, 2017 12:38
@jplock jplock added the feature label Feb 27, 2017
nickbabcock added a commit that referenced this pull request Mar 8, 2017
nickbabcock added a commit that referenced this pull request Mar 8, 2017
aaanders pushed a commit to aaanders/dropwizard that referenced this pull request Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants