Page MenuHomePhabricator

D10513.id.diff
No OneTemporary

D10513.id.diff

diff --git a/src/applications/drydock/blueprint/DrydockMinMaxBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockMinMaxBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockMinMaxBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockMinMaxBlueprintImplementation.php
@@ -5,7 +5,58 @@
public function canAllocateMoreResources(array $pool) {
$max_count = $this->getDetail('max-count');
- return $max_count === null || count($pool) < $max_count;
+
+ if ($max_count === null) {
+ $this->log(pht(
+ 'There is no maximum resource limit specified for this blueprint'));
+ return true;
+ }
+
+ $count_pending = 0;
+ $count_allocating = 0;
+ $count_open = 0;
+
+ foreach ($pool as $resource) {
+ switch ($resource->getStatus()) {
+ case DrydockResourceStatus::STATUS_PENDING:
+ $count_pending++;
+ break;
+ case DrydockResourceStatus::STATUS_ALLOCATING:
+ $count_allocating++;
+ break;
+ case DrydockResourceStatus::STATUS_OPEN:
+ $count_open++;
+ break;
+ default:
+ $this->log(pht(
+ 'Resource %d was in the pool of open resources, '.
+ 'but has non-open status of %d',
+ $resource->getID(),
+ $resource->getStatus()));
+ break;
+ }
+ }
+
+ $this->log(pht(
+ 'There are currently %d pending resources, %d allocating resources '.
+ 'and %d open resources in the pool.',
+ $count_pending,
+ $count_allocating,
+ $count_open));
+
+ if (count($pool) < $max_count) {
+ $this->log(pht(
+ 'Will permit resource allocation because %d is less than the maximum '.
+ 'of %d.',
+ count($pool),
+ $max_count));
+ } else {
+ $this->log(pht(
+ 'Will deny resource allocation because %d is less than the maximum '.
+ 'of %d.',
+ count($pool),
+ $max_count));
+ }
}
protected function shouldAllocateLease(
diff --git a/src/applications/drydock/blueprint/DrydockMinMaxExpiryBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockMinMaxExpiryBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockMinMaxExpiryBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockMinMaxExpiryBlueprintImplementation.php
@@ -7,7 +7,7 @@
$max_count = $this->getDetail('max-count');
if ($max_count === null) {
- return true;
+ return parent::canAllocateMoreResources($pool);
}
$expiry = $this->getDetail('expiry');
@@ -24,21 +24,16 @@
// Only count resources that haven't yet expired, so we can overallocate
// if another expired resource is about to be closed (but is still waiting
// on it's current resources to be released).
- $count = 0;
$now = time();
+ $pool_copy = array();
foreach ($pool as $resource) {
$lifetime = $now - $resource->getDateCreated();
- if ($lifetime <= $expiry) {
- $count++;
+ if ($lifetime > $expiry) {
+ $pool_copy[] = $resource;
}
}
- $this->log(pht(
- 'Can allocate if %d is less than %d',
- $count,
- $max_count));
-
- return $count < $max_count;
+ return parent::canAllocateMoreResources($pool_copy);
}
protected function shouldAllocateLease(

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 29, 1:57 PM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7714492
Default Alt Text
D10513.id.diff (3 KB)

Event Timeline