Page MenuHomePhabricator

D14210.diff
No OneTemporary

D14210.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -831,6 +831,8 @@
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php',
'DrydockLeaseActivatedLogType' => 'applications/drydock/logtype/DrydockLeaseActivatedLogType.php',
+ 'DrydockLeaseActivationFailureLogType' => 'applications/drydock/logtype/DrydockLeaseActivationFailureLogType.php',
+ 'DrydockLeaseActivationYieldLogType' => 'applications/drydock/logtype/DrydockLeaseActivationYieldLogType.php',
'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php',
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php',
@@ -845,6 +847,7 @@
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
+ 'DrydockLeaseWaitingForResourcesLogType' => 'applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php',
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php',
'DrydockLogGarbageCollector' => 'applications/drydock/garbagecollector/DrydockLogGarbageCollector.php',
@@ -862,6 +865,8 @@
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php',
'DrydockQuery' => 'applications/drydock/query/DrydockQuery.php',
'DrydockResource' => 'applications/drydock/storage/DrydockResource.php',
+ 'DrydockResourceActivationFailureLogType' => 'applications/drydock/logtype/DrydockResourceActivationFailureLogType.php',
+ 'DrydockResourceActivationYieldLogType' => 'applications/drydock/logtype/DrydockResourceActivationYieldLogType.php',
'DrydockResourceController' => 'applications/drydock/controller/DrydockResourceController.php',
'DrydockResourceDatasource' => 'applications/drydock/typeahead/DrydockResourceDatasource.php',
'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php',
@@ -877,6 +882,7 @@
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
'DrydockSlotLock' => 'applications/drydock/storage/DrydockSlotLock.php',
'DrydockSlotLockException' => 'applications/drydock/exception/DrydockSlotLockException.php',
+ 'DrydockSlotLockFailureLogType' => 'applications/drydock/logtype/DrydockSlotLockFailureLogType.php',
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
'DrydockWorker' => 'applications/drydock/worker/DrydockWorker.php',
'DrydockWorkingCopyBlueprintImplementation' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php',
@@ -4571,6 +4577,8 @@
),
'DrydockLeaseAcquiredLogType' => 'DrydockLogType',
'DrydockLeaseActivatedLogType' => 'DrydockLogType',
+ 'DrydockLeaseActivationFailureLogType' => 'DrydockLogType',
+ 'DrydockLeaseActivationYieldLogType' => 'DrydockLogType',
'DrydockLeaseController' => 'DrydockController',
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
'DrydockLeaseDestroyedLogType' => 'DrydockLogType',
@@ -4585,6 +4593,7 @@
'DrydockLeaseStatus' => 'DrydockConstants',
'DrydockLeaseUpdateWorker' => 'DrydockWorker',
'DrydockLeaseViewController' => 'DrydockLeaseController',
+ 'DrydockLeaseWaitingForResourcesLogType' => 'DrydockLogType',
'DrydockLog' => array(
'DrydockDAO',
'PhabricatorPolicyInterface',
@@ -4608,6 +4617,8 @@
'DrydockDAO',
'PhabricatorPolicyInterface',
),
+ 'DrydockResourceActivationFailureLogType' => 'DrydockLogType',
+ 'DrydockResourceActivationYieldLogType' => 'DrydockLogType',
'DrydockResourceController' => 'DrydockController',
'DrydockResourceDatasource' => 'PhabricatorTypeaheadDatasource',
'DrydockResourceListController' => 'DrydockResourceController',
@@ -4623,6 +4634,7 @@
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
'DrydockSlotLock' => 'DrydockDAO',
'DrydockSlotLockException' => 'Exception',
+ 'DrydockSlotLockFailureLogType' => 'DrydockLogType',
'DrydockWebrootInterface' => 'DrydockInterface',
'DrydockWorker' => 'PhabricatorWorker',
'DrydockWorkingCopyBlueprintImplementation' => 'DrydockBlueprintImplementation',
diff --git a/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
@@ -172,14 +172,16 @@
// Destroy the lease on the host.
$lease->releaseOnDestruction();
- // Destroy the working copy on disk.
- $command_type = DrydockCommandInterface::INTERFACE_TYPE;
- $interface = $lease->getInterface($command_type);
-
- $root_key = 'workingcopy.root';
- $root = $resource->getAttribute($root_key);
- if (strlen($root)) {
- $interface->execx('rm -rf -- %s', $root);
+ if ($lease->isActive()) {
+ // Destroy the working copy on disk.
+ $command_type = DrydockCommandInterface::INTERFACE_TYPE;
+ $interface = $lease->getInterface($command_type);
+
+ $root_key = 'workingcopy.root';
+ $root = $resource->getAttribute($root_key);
+ if (strlen($root)) {
+ $interface->execx('rm -rf -- %s', $root);
+ }
}
}
diff --git a/src/applications/drydock/exception/DrydockSlotLockException.php b/src/applications/drydock/exception/DrydockSlotLockException.php
--- a/src/applications/drydock/exception/DrydockSlotLockException.php
+++ b/src/applications/drydock/exception/DrydockSlotLockException.php
@@ -22,4 +22,8 @@
parent::__construct($message);
}
+ public function getLockMap() {
+ return $this->lockMap;
+ }
+
}
diff --git a/src/applications/drydock/logtype/DrydockLeaseActivationFailureLogType.php b/src/applications/drydock/logtype/DrydockLeaseActivationFailureLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseActivationFailureLogType.php
@@ -0,0 +1,22 @@
+<?php
+
+final class DrydockLeaseActivationFailureLogType extends DrydockLogType {
+
+ const LOGCONST = 'core.lease.activation-failure';
+
+ public function getLogTypeName() {
+ return pht('Activation Failed');
+ }
+
+ public function getLogTypeIcon(array $data) {
+ return 'fa-times red';
+ }
+
+ public function renderLog(array $data) {
+ $class = idx($data, 'class');
+ $message = idx($data, 'message');
+
+ return pht('Lease activation failed: [%s] %s', $class, $message);
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLeaseActivationYieldLogType.php b/src/applications/drydock/logtype/DrydockLeaseActivationYieldLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseActivationYieldLogType.php
@@ -0,0 +1,23 @@
+<?php
+
+final class DrydockLeaseActivationYieldLogType extends DrydockLogType {
+
+ const LOGCONST = 'core.lease.activation-yield';
+
+ public function getLogTypeName() {
+ return pht('Waiting for Activation');
+ }
+
+ public function getLogTypeIcon(array $data) {
+ return 'fa-clock-o green';
+ }
+
+ public function renderLog(array $data) {
+ $duration = idx($data, 'duration');
+
+ return pht(
+ 'Waiting %s second(s) for lease to activate.',
+ new PhutilNumber($duration));
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php b/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php
@@ -0,0 +1,25 @@
+<?php
+
+final class DrydockLeaseWaitingForResourcesLogType extends DrydockLogType {
+
+ const LOGCONST = 'core.lease.waiting-for-resources';
+
+ public function getLogTypeName() {
+ return pht('Waiting For Resource');
+ }
+
+ public function getLogTypeIcon(array $data) {
+ return 'fa-clock-o yellow';
+ }
+
+ public function renderLog(array $data) {
+ $viewer = $this->getViewer();
+
+ $blueprint_phids = idx($data, 'blueprintPHIDs', array());
+
+ return pht(
+ 'Waiting for available resources from: %s.',
+ $viewer->renderHandleList($blueprint_phids));
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockResourceActivationFailureLogType.php b/src/applications/drydock/logtype/DrydockResourceActivationFailureLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockResourceActivationFailureLogType.php
@@ -0,0 +1,22 @@
+<?php
+
+final class DrydockResourceActivationFailureLogType extends DrydockLogType {
+
+ const LOGCONST = 'core.resource.activation-failure';
+
+ public function getLogTypeName() {
+ return pht('Activation Failed');
+ }
+
+ public function getLogTypeIcon(array $data) {
+ return 'fa-times red';
+ }
+
+ public function renderLog(array $data) {
+ $class = idx($data, 'class');
+ $message = idx($data, 'message');
+
+ return pht('Resource activation failed: [%s] %s', $class, $message);
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockResourceActivationYieldLogType.php b/src/applications/drydock/logtype/DrydockResourceActivationYieldLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockResourceActivationYieldLogType.php
@@ -0,0 +1,23 @@
+<?php
+
+final class DrydockResourceActivationYieldLogType extends DrydockLogType {
+
+ const LOGCONST = 'core.resource.activation-yield';
+
+ public function getLogTypeName() {
+ return pht('Waiting for Activation');
+ }
+
+ public function getLogTypeIcon(array $data) {
+ return 'fa-clock-o green';
+ }
+
+ public function renderLog(array $data) {
+ $duration = idx($data, 'duration');
+
+ return pht(
+ 'Waiting %s second(s) for resource to activate.',
+ new PhutilNumber($duration));
+ }
+
+}
diff --git a/src/applications/drydock/logtype/DrydockSlotLockFailureLogType.php b/src/applications/drydock/logtype/DrydockSlotLockFailureLogType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/logtype/DrydockSlotLockFailureLogType.php
@@ -0,0 +1,26 @@
+<?php
+
+final class DrydockSlotLockFailureLogType extends DrydockLogType {
+
+ const LOGCONST = 'core.resource.slot-lock.failure';
+
+ public function getLogTypeName() {
+ return pht('Slot Lock Failure');
+ }
+
+ public function getLogTypeIcon(array $data) {
+ return 'fa-lock yellow';
+ }
+
+ public function renderLog(array $data) {
+ $locks = idx($data, 'locks', array());
+ if ($locks) {
+ return pht(
+ 'Failed to acquire slot locks: %s.',
+ implode(', ', array_keys($locks)));
+ } else {
+ return pht('Failed to acquire slot locks.');
+ }
+ }
+
+}
diff --git a/src/applications/drydock/storage/DrydockLease.php b/src/applications/drydock/storage/DrydockLease.php
--- a/src/applications/drydock/storage/DrydockLease.php
+++ b/src/applications/drydock/storage/DrydockLease.php
@@ -232,16 +232,28 @@
}
$this->openTransaction();
+ try {
+ try {
+ DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
+ $this->slotLocks = array();
+ } catch (DrydockSlotLockException $ex) {
+ $this->logEvent(
+ DrydockSlotLockFailureLogType::LOGCONST,
+ array(
+ 'locks' => $ex->getLockMap(),
+ ));
+ throw $ex;
+ }
$this
->setResourcePHID($resource->getPHID())
->attachResource($resource)
->setStatus($new_status)
->save();
-
- DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
- $this->slotLocks = array();
-
+ } catch (Exception $ex) {
+ $this->killTransaction();
+ throw $ex;
+ }
$this->saveTransaction();
$this->isAcquired = true;
diff --git a/src/applications/drydock/storage/DrydockResource.php b/src/applications/drydock/storage/DrydockResource.php
--- a/src/applications/drydock/storage/DrydockResource.php
+++ b/src/applications/drydock/storage/DrydockResource.php
@@ -135,15 +135,30 @@
$new_status = DrydockResourceStatus::STATUS_PENDING;
}
+ $phid = $this->generatePHID();
+
$this->openTransaction();
+ try {
+ try {
+ DrydockSlotLock::acquireLocks($phid, $this->slotLocks);
+ $this->slotLocks = array();
+ } catch (DrydockSlotLockException $ex) {
+ $this->logEvent(
+ DrydockSlotLockFailureLogType::LOGCONST,
+ array(
+ 'locks' => $ex->getLockMap(),
+ ));
+ throw $ex;
+ }
$this
+ ->setPHID($phid)
->setStatus($new_status)
->save();
-
- DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
- $this->slotLocks = array();
-
+ } catch (Exception $ex) {
+ $this->killTransaction();
+ throw $ex;
+ }
$this->saveTransaction();
$this->isAllocated = true;
@@ -257,6 +272,18 @@
}
}
+ public function logEvent($type, array $data = array()) {
+ $log = id(new DrydockLog())
+ ->setEpoch(PhabricatorTime::getNow())
+ ->setType($type)
+ ->setData($data);
+
+ $log->setResourcePHID($this->getPHID());
+ $log->setBlueprintPHID($this->getBlueprintPHID());
+
+ return $log->save();
+ }
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 9, 12:26 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7388762
Default Alt Text
D14210.diff (13 KB)

Event Timeline