-
Notifications
You must be signed in to change notification settings - Fork 248
LB paginator fix #521
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
Merged
ycombinator
merged 9 commits into
rackspace:working
from
jamiehannaford:lb-paginator-fix
Jan 15, 2015
Merged
LB paginator fix #521
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d08b30b
Merge pull request #506 from rgbkrk/containerized_travis
ycombinator 249d0e3
Merge branch 'working' of https://github.com/rackspace/php-opencloud …
f965348
Add mock HTTP responses
e5f57b5
Decouple the process of retrieving last element from setting marker
9cd0db1
Add new iterator to handle differences
3f69dfd
Implement into service and refactor tests
622d76d
Appease PSR-2 gods
6895f84
Attempt to fix 5.3 segfault
48e1df4
Tweaks based on code review
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 hidden or 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
39 changes: 39 additions & 0 deletions
39
lib/OpenCloud/LoadBalancer/Collection/LoadBalancerIterator.php
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace OpenCloud\LoadBalancer\Collection; | ||
|
||
use OpenCloud\Common\Collection\PaginatedIterator; | ||
|
||
class LoadBalancerIterator extends PaginatedIterator | ||
{ | ||
private $nextElement; | ||
|
||
public function constructNextUrl() | ||
{ | ||
$url = parent::constructNextUrl(); | ||
|
||
// We need to return n+1 items in order to grab the relevant marker value | ||
$query = $url->getQuery(); | ||
$query['limit'] = $query['limit'] + 1; | ||
$url->setQuery($query); | ||
|
||
return $url; | ||
} | ||
|
||
public function updateMarkerToCurrent() | ||
{ | ||
$this->setMarkerFromElement($this->nextElement); | ||
} | ||
|
||
public function parseResponseBody($body) | ||
{ | ||
$response = parent::parseResponseBody($body); | ||
|
||
if (count($response) >= $this->getOption('limit.page')) { | ||
// Pop last element and save (we will need it for the next marker) | ||
$this->nextElement = array_pop($response); | ||
} | ||
|
||
return $response; | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
tests/OpenCloud/Tests/LoadBalancer/_response/LoadBalancers1.resp
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
HTTP/1.1 200 OK | ||
Status: 200 OK | ||
Date: Thu, 28 Jul 2011 21:54:21 GMT | ||
X-API-VERSION: 1.0.17 | ||
Content-Type: application/json | ||
Content-Length: 1975 | ||
|
||
{ | ||
"loadBalancers":[ | ||
{ | ||
"name":"lb-site1", | ||
"id":1, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":3, | ||
"virtualIps":[ | ||
{ | ||
"id":403, | ||
"address":"206.55.130.1", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
}, | ||
{ | ||
"name":"lb-site2", | ||
"id":2, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":4, | ||
"virtualIps":[ | ||
{ | ||
"id":401, | ||
"address":"206.55.130.2", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
}, | ||
{ | ||
"name":"lb-site3", | ||
"id":3, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":4, | ||
"virtualIps":[ | ||
{ | ||
"id":401, | ||
"address":"206.55.130.2", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
} | ||
] | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/OpenCloud/Tests/LoadBalancer/_response/LoadBalancers2.resp
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
HTTP/1.1 200 OK | ||
Status: 200 OK | ||
Date: Thu, 28 Jul 2011 21:54:21 GMT | ||
X-API-VERSION: 1.0.17 | ||
Content-Type: application/json | ||
Content-Length: 1975 | ||
|
||
{ | ||
"loadBalancers":[ | ||
{ | ||
"name":"lb-site3", | ||
"id":3, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":4, | ||
"virtualIps":[ | ||
{ | ||
"id":401, | ||
"address":"206.55.130.2", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
}, | ||
{ | ||
"name":"lb-site4", | ||
"id":4, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":4, | ||
"virtualIps":[ | ||
{ | ||
"id":401, | ||
"address":"206.55.130.2", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
}, | ||
{ | ||
"name":"lb-site5", | ||
"id":5, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":4, | ||
"virtualIps":[ | ||
{ | ||
"id":401, | ||
"address":"206.55.130.2", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
} | ||
] | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/OpenCloud/Tests/LoadBalancer/_response/LoadBalancers3.resp
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
HTTP/1.1 200 OK | ||
Status: 200 OK | ||
Date: Thu, 28 Jul 2011 21:54:21 GMT | ||
X-API-VERSION: 1.0.17 | ||
Content-Type: application/json | ||
Content-Length: 1975 | ||
|
||
{ | ||
"loadBalancers":[ | ||
{ | ||
"name":"lb-site5", | ||
"id":5, | ||
"protocol":"HTTP", | ||
"port":80, | ||
"algorithm":"RANDOM", | ||
"status":"ACTIVE", | ||
"nodeCount":4, | ||
"virtualIps":[ | ||
{ | ||
"id":401, | ||
"address":"206.55.130.2", | ||
"type":"PUBLIC", | ||
"ipVersion":"IPV4" | ||
} | ||
], | ||
"created":{ | ||
"time":"2010-11-30T03:23:42Z" | ||
}, | ||
"updated":{ | ||
"time":"2010-11-30T03:23:44Z" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or 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
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 you add a comment here explaining why this the next 2 statements are necessary? I'm particularly curious about the
unset
.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 guess they aren't needed. I was thinking of these lines and wanted to have the iterator set the query value rather than couple it to the user's input. But thinking about it, it doesn't matter: either way the query is set and the URL will have the appropriate value.
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.
How will the URL have the appropriate value without you explicitly setting
$options['limit.page']
? Is it part of the paginated "next page" URL returned in the API response?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 base URL that is passed in as an option to the iterator is subsequently used to construct next URLs. If the query value is set on the initial URL, then it should still be set when the iterator constructs the next one.
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.
Understood. Thanks.