-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Reorg and refactor repo - continued #1684
Conversation
@@ -27,10 +29,37 @@ | |||
*/ | |||
public class Authorization { | |||
|
|||
/** |
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.
note to reviewers: these are just moved from Authorizations
.
jib-core/src/main/java/com/google/cloud/tools/jib/event/progress/DelayedConsumer.java
Outdated
Show resolved
Hide resolved
Ready for review. |
* @param blobProgressListener listener for progress of the pull | ||
* @param blobSizeListener callback to receive the total size of the BLOb to pull | ||
* @param writtenByteCountListener listens on byte count written to an output stream during the | ||
* pull | ||
* @return a {@link Blob} | ||
*/ | ||
public Blob pullBlob( |
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.
Maybe it could be simpler if these blob pull/push clsases took a single ProgressEventDispatcherWrapper
with the set/dispatch methods instead of two consumers? I'm not sure how it fits into the class hierarchy though.
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.
That's true it will look simpler technically. But my intent is actually decouple ProgressEventDispatcherWrapper
from RegistryClient
, which I think makes sense from the API perspective because this ProgressEventDispatcherWrapper
is too specific in that it is an unfortunate wrapper required to lazily instantiate ProgressEventDispatcher
. I think this class can remain general and free of progress event dispatcher stuff, especially the wrapper. That way I specifically named them writtenByCountListener
instead of, say, progressEventDispatcher
.
@@ -65,8 +57,9 @@ public void close() { | |||
progressEventDispatcher.close(); | |||
} | |||
|
|||
void initializeWithBlobSize(long blobSize) { | |||
void setProgressTarget(long allocationUnits) { |
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.
Seems a bit weird to have to call the constructor and this method to fully initialize a ProgressEventDispatcherWrapper
, maybe we can consolidate this by changing the signature of RegistryClient#pullBlob
?
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.
Yeah, I did not like this wrapper either. The problem Q originally faced was the progress reporting design that
- You have to know and set in advance how much progress units you will allocate when creating a progress event dispatcher.
- But you cannot know how much bytes (allocation units) you will download until you read
Content-Length
. - So the wrapper that will create and hold a progress event dispatcher when this method is called. Other than that, this class is just a thin wrapper that delegates
dispatchProgress()
.
For this reason, obviously it's best to get rid of this unfortunate wrapper if possible. As an attempt to work around the issue, Q probably also felt it doesn't make much sense to have this wrapper in the signature and make it a hard dependency from the API standpoint, also given that there are only just a couple places this wrapper is required. And as I said in the earlier comment, my intention is to actually decouple progress dispatcher stuff from RegistryClient
.
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.
Some comments from the half-way mark.
jib-core/src/main/java/com/google/cloud/tools/jib/event/progress/DelayedConsumer.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/event/progress/DelayedConsumer.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/hash/CountingDigestOutputStream.java
Show resolved
Hide resolved
* resets after this method is called, so this method should only be called once per computation. | ||
* Computes the hash and returns it along with the size of the bytes written to compute the hash. | ||
* The buffer resets after this method is called, so this method should only be called once per | ||
* computation. |
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.
I wonder how many places do we call this method multiple times?
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.
I'm guessing none, because the last time I touched this class, it was reporting wrong bytes when called more than once. (Basically, bytesSoFar
was not reset.)
jib-core/src/main/java/com/google/cloud/tools/jib/http/BlobHttpContent.java
Outdated
Show resolved
Hide resolved
I've addressed the comments. This should be good now. |
jib-core/src/main/java/com/google/cloud/tools/jib/event/progress/ThrottledConsumer.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/http/Authorization.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/event/progress/ThrottledLongConsumer.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/hash/Digests.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/http/ListenableCountingOutputStream.java
Outdated
Show resolved
Hide resolved
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.
looks good to me, unless @briandealwis has any further questions?
this(blob, contentType, ignored -> {}); | ||
} | ||
|
||
public BlobHttpContent(Blob blob, String contentType, Consumer<Long> writtenByteCountListener) { |
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.
It seems weird that a content object carries a listener — it's entirely possible this content object could be written out multiple times.
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.
Makes sense. Not immediately clear how I can change this though.
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.
Should it not contain a writeTo? Or should writeTo take the listener?
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.
The class is implementing HttpContent::writeTo
, so it's not like we can simply change the signature at this level. Perhaps next time.
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.
Ah interesting, didn't know HttpContent was something outside of our codebase.
For Blob changes, following the same spirit in #1647 and #1678.
Other changes involve removing various classes around progress reporting, decoupling functionalities to have small, fine-grained general components, etc.