-
-
Notifications
You must be signed in to change notification settings - Fork 55
Implemented more API complete container listing #315
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
Conversation
Pull Request Test Coverage Report for Build 585
💛 - Coveralls |
@amihaiemil Is test coverage for contributed code a hard requirement? |
This pull request #315 is assigned to @paulodamaso/z, here is why; the budget is 15 minutes, see §4; please, read §27 and when you decide to accept the changes, inform @amihaiemil/z (the architect) right in this ticket; if you decide that this PR should not be accepted ever, also inform the architect; this blog post will help you understand what is expected from a code reviewer; there will be a monetary reward for this job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux I have some comments, please take a look.
* @return Filtered containers. | ||
* @see <a href="https://docs.docker.com/engine/api/v1.35/#operation/ContainerList">Docker API Docs</a> | ||
*/ | ||
Containers filter(Map<String, Iterable<String>> filters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux I think that this should be implemented as a decorator called Filtered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but I'm a bit puzzled because I did my implementation in line with the patterns I found in RtImages
and ListedImages
, and now you suggest a completely different pattern that has not been used in the library AFAICT.
Also, decorator patterns are applicable to one class only, because a decorator cannot expose functionality of multiple classes, right?
However, I think we could indeed improve code quality by defining this method in a separate interface (e.g. Filterable
) and implementing that in all classes with that functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux In this case we don't need essentially another interface; a Filtered
would decorate a Containers
object and execute the filtering of the values as needed. But we can develop a new Filterable
interface, which will retain the filtering logic for all filterable elements (containers, images and so on). It is indeed a fine solution. @amihaiemil WDYT about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I think we have to get some things straight here, because afaik the decorator pattern is an approach that simply doesn't make any sense here. It's almost like saying "let's use the observer pattern here". Please let me explain why I think so:
We could use the decorator pattern, whereas our decorator contains more or less precisely the same code as ListedContainers
, plus a bunch of proxy methods that forward calls to the original RtContainer
instance. We cannot remove all()
and iterator()
, because they need information about the filters and/or size flag to construct the API request, and the underlying implementation is per definition unaware of the wrapping decorator when using this pattern. Thus, we end up with a lot of code duplication, because we need to implement all()
and iterator()
twice, once for RtContainer
and once for the decorator.
Maybe I'm an idiot and got your excellent idea all wrong, but I believe there might be an implicit error in your imagination about how this should work. If you still think decorators are a good idea, then please elaborate a bit more on this.
* @param withSize Return the size of containers (SizeRw and SizeRootFs). | ||
* @return Containers with modified size flag. | ||
*/ | ||
Containers withSize(final boolean withSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux I think that this could be implemented as a decorator to Containers
, which returns decorated Container
objects with size information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, maybe another interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux If we have the fields SizeRw
and SizeRootFs
for more API elements, then I think that an WithSize
or Sized
(I can't think in a good name for this) interface would be fine. But also, I think that we could create these objects inside a Containers
decorator which returns only Sized
objects. @amihaiemil how about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here is the decorator once again... see above. 😉
* @version $Id$ | ||
* @since 0.0.11 | ||
*/ | ||
final class ListedContainers extends RtContainers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux Take a look to the comments above; after they are implemented this class may be not necessary and those behaviors can come back to RtContainers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we could move this functionality to RtContainers
, but this is against the good pattern that I found with similar APIs in that library, where Sub-API-calls go to an abstract base class whereas concrete implementations for filter etc. go to a ListedXYZ
class.
Do you really consider this a good idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux In this case we would have iterator
and all
methods moved to the abstract class. The other methods would be implemented by their corresponding interfaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're aware that interfaces do only define a contract/interface (thus their name...) and cannot contain any implementation?
Interface-like constructs that contain actual implementations, best known as traits, or other concepts for multiple inheritance are not available in Java.
We could move the project to Kotlin, though, then there are traits. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And moving iterator
and all
to a base class that's not aware of filters and flags is not possible for the reasons explained above, unless you start to copy-paste the code to multiple levels of inheritance (or nesting in case of decorators) which is a terrible idea in terms of software design.
@milux @paulodamaso Whatever the implementation details are, it doesn't matter as long as we can agree on the interfaces and class encapsulation. Maybe @milux will provide more PRs, so we can adjust implementation details on the go. @milux As guidelines, whenever you want to provide a PR, open an Issue about it first, so we can discuss there your ideas before you make a PR, it will be easier. |
@amihaiemil I totally agree, however, you may want to update your README to reflect this, because it now says |
What's missing for merge? Test coverage? Anything else? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux @amihaiemil Please take a look at the comments
* @return Filtered containers. | ||
* @see <a href="https://docs.docker.com/engine/api/v1.35/#operation/ContainerList">Docker API Docs</a> | ||
*/ | ||
Containers filter(Map<String, Iterable<String>> filters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux In this case we don't need essentially another interface; a Filtered
would decorate a Containers
object and execute the filtering of the values as needed. But we can develop a new Filterable
interface, which will retain the filtering logic for all filterable elements (containers, images and so on). It is indeed a fine solution. @amihaiemil WDYT about this?
* @param withSize Return the size of containers (SizeRw and SizeRootFs). | ||
* @return Containers with modified size flag. | ||
*/ | ||
Containers withSize(final boolean withSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux If we have the fields SizeRw
and SizeRootFs
for more API elements, then I think that an WithSize
or Sized
(I can't think in a good name for this) interface would be fine. But also, I think that we could create these objects inside a Containers
decorator which returns only Sized
objects. @amihaiemil how about?
* @version $Id$ | ||
* @since 0.0.11 | ||
*/ | ||
final class ListedContainers extends RtContainers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milux In this case we would have iterator
and all
methods moved to the abstract class. The other methods would be implemented by their corresponding interfaces
@milux @paulodamaso Guys, you seem to be having a long conversation I am honestly a bit lazy to follow. Just agree on the interface and details of implementation can be fixed later. @milux About Decorator: we do use Decorator extensively. We believe Decorator is the most important pattern in OOP. We are actually practicing a more or less novel kind of OOP, called "Elegant Objects": https://www.elegantobjects.org/ I'm not sure what you guys are discussing about a Filtered pattern, but here is an example of such a Thanks, |
@milux And anyway, I remember I have already implemented some Filtering in the library, somewhere. Is it not possible to follow that same pattern? If you are following that same pattern, then it's ok :) I would just ask you to not decrease Test Coverage :D |
I am following the exact same pattern you have used in |
Please see above, your comments somehow got duplicated as far as I can tell, and I commented above. |
@milux If it's the same pattern, it's fine. Just please don't decrease test coverage. Is it possible or too complicated? :D @paulodamaso Let this one to me please :D |
Fun fact: It's exactly what you described in https://amihaiemil.com/2018/11/10/an-extension-to-telldontask.html, and I don't get how @paulodamaso wants to apply the decorator pattern here, see above. I really don't want to be rude to anybody, but to me the suggestion just doesn't make any sense. Maybe @paulodamaso and I are simply talking at cross purposes... Regarding the test coverage: Agreed, working on it... |
@amihaiemil Unit tests implemented, overall coverage has increased. 😄 |
@milux Don'ty worry about being rude, you aren't. Just for clarifying the idea about decorators. I was thinking in something like this:
The idea became clearer? Does it make sense? |
@milux Vielen Dank! However, Rultor has problems still. I am trying to fix the issue as soon as possible so we can release 0.0.11. See the latest opened Issue for the progress... |
Job was finished in 29 hours, bonus for fast delivery is possible (see §36) |
Order was finished: +20 point(s) just awarded to @paulodamaso/z |
Payment to |
This PR extends the container listing API documented in https://docs.docker.com/engine/api/v1.35/#operation/ContainerList.
All parameters except
limit
are now supported, especiallysize
andfilters
.