-
Notifications
You must be signed in to change notification settings - Fork 234
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
[YUNIKORN-2249] Add compression option to getQueueApplication API #757
Open
targetoee
wants to merge
20
commits into
apache:master
Choose a base branch
from
targetoee:YUNIKORN-2249
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9ef7968
add compression part
targetoee 85dd3de
add compression part
targetoee b5e2651
modify compress function and add test
targetoee e7ea5bc
Merge branch 'master' into YUNIKORN-2249
targetoee 7238626
fix lint
targetoee ce40af6
pull origin branch
targetoee 995cb97
close writer and check supported comp type
targetoee 4cb1d9c
skip compress step if the data size is small
targetoee 40b9649
correct header setting
targetoee 4f57568
modify compress & checkheader function
targetoee 4e7228a
remove unused testcase
targetoee 2205902
unused import
targetoee b811993
draft testcase
targetoee 8a6f9cf
handle compression in unified manner
targetoee 53c8827
Merge branch 'master' into YUNIKORN-2249
targetoee 1c4a0e1
fix test
targetoee 41c0570
add compression test case
targetoee ca18e79
add webservice test
targetoee 0a6c931
adjust error message and close connection immediately
targetoee 3f806ba
adjust function name and message
targetoee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
package webservice | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
|
@@ -614,6 +616,33 @@ | |
appsDao = append(appsDao, getApplicationDAO(app)) | ||
} | ||
|
||
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing for
|
||
w.Header().Set("Content-Encoding", "gzip") | ||
|
||
response, err := json.Marshal(appsDao) | ||
if err != nil { | ||
buildJSONErrorResponse(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
var comp bytes.Buffer | ||
writer := gzip.NewWriter(&comp) | ||
_, err = writer.Write(response) | ||
if err != nil { | ||
buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
err = writer.Close() | ||
if err != nil { | ||
buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
if _, err = w.Write(comp.Bytes()); err != nil { | ||
buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
return | ||
} | ||
|
||
if err := json.NewEncoder(w).Encode(appsDao); err != nil { | ||
buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we have test for gzip header?
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.
Can we try to make it modular? We already thinking of doing it in two more places. We should be able to use the method wherever required.
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.
const
section, it's better for maintainability. We have string literals all over the place, eg.writeHeaders()
. I don't think we need to import a separate library for this, but at least have a single place where all of them are defined. Also do the same for MIME types.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.
By modular I mean create two functions. One that tests for the header content see other review point and one that does all the compress work and takes two parameters and returns nothing. We can use that compress function anywhere.
Need to file a follow up jira when we add this to add support for all REST endpoints to support compressed data...