@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add more Drydock log types and some additional logging

Summary: Ref T9252. Add a bit more logging and improve some behaviors.

Test Plan: Restarted a build, got a good result.

Reviewers: chad, hach-que

Reviewed By: hach-que

Maniphest Tasks: T9252

Differential Revision: https://secure.phabricator.com/D14210

+213 -15
+12
src/__phutil_library_map__.php
··· 831 831 'DrydockLease' => 'applications/drydock/storage/DrydockLease.php', 832 832 'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php', 833 833 'DrydockLeaseActivatedLogType' => 'applications/drydock/logtype/DrydockLeaseActivatedLogType.php', 834 + 'DrydockLeaseActivationFailureLogType' => 'applications/drydock/logtype/DrydockLeaseActivationFailureLogType.php', 835 + 'DrydockLeaseActivationYieldLogType' => 'applications/drydock/logtype/DrydockLeaseActivationYieldLogType.php', 834 836 'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php', 835 837 'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php', 836 838 'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php', ··· 845 847 'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php', 846 848 'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php', 847 849 'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php', 850 + 'DrydockLeaseWaitingForResourcesLogType' => 'applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php', 848 851 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', 849 852 'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php', 850 853 'DrydockLogGarbageCollector' => 'applications/drydock/garbagecollector/DrydockLogGarbageCollector.php', ··· 862 865 'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php', 863 866 'DrydockQuery' => 'applications/drydock/query/DrydockQuery.php', 864 867 'DrydockResource' => 'applications/drydock/storage/DrydockResource.php', 868 + 'DrydockResourceActivationFailureLogType' => 'applications/drydock/logtype/DrydockResourceActivationFailureLogType.php', 869 + 'DrydockResourceActivationYieldLogType' => 'applications/drydock/logtype/DrydockResourceActivationYieldLogType.php', 865 870 'DrydockResourceController' => 'applications/drydock/controller/DrydockResourceController.php', 866 871 'DrydockResourceDatasource' => 'applications/drydock/typeahead/DrydockResourceDatasource.php', 867 872 'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php', ··· 877 882 'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php', 878 883 'DrydockSlotLock' => 'applications/drydock/storage/DrydockSlotLock.php', 879 884 'DrydockSlotLockException' => 'applications/drydock/exception/DrydockSlotLockException.php', 885 + 'DrydockSlotLockFailureLogType' => 'applications/drydock/logtype/DrydockSlotLockFailureLogType.php', 880 886 'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php', 881 887 'DrydockWorker' => 'applications/drydock/worker/DrydockWorker.php', 882 888 'DrydockWorkingCopyBlueprintImplementation' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php', ··· 4571 4577 ), 4572 4578 'DrydockLeaseAcquiredLogType' => 'DrydockLogType', 4573 4579 'DrydockLeaseActivatedLogType' => 'DrydockLogType', 4580 + 'DrydockLeaseActivationFailureLogType' => 'DrydockLogType', 4581 + 'DrydockLeaseActivationYieldLogType' => 'DrydockLogType', 4574 4582 'DrydockLeaseController' => 'DrydockController', 4575 4583 'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource', 4576 4584 'DrydockLeaseDestroyedLogType' => 'DrydockLogType', ··· 4585 4593 'DrydockLeaseStatus' => 'DrydockConstants', 4586 4594 'DrydockLeaseUpdateWorker' => 'DrydockWorker', 4587 4595 'DrydockLeaseViewController' => 'DrydockLeaseController', 4596 + 'DrydockLeaseWaitingForResourcesLogType' => 'DrydockLogType', 4588 4597 'DrydockLog' => array( 4589 4598 'DrydockDAO', 4590 4599 'PhabricatorPolicyInterface', ··· 4608 4617 'DrydockDAO', 4609 4618 'PhabricatorPolicyInterface', 4610 4619 ), 4620 + 'DrydockResourceActivationFailureLogType' => 'DrydockLogType', 4621 + 'DrydockResourceActivationYieldLogType' => 'DrydockLogType', 4611 4622 'DrydockResourceController' => 'DrydockController', 4612 4623 'DrydockResourceDatasource' => 'PhabricatorTypeaheadDatasource', 4613 4624 'DrydockResourceListController' => 'DrydockResourceController', ··· 4623 4634 'DrydockSSHCommandInterface' => 'DrydockCommandInterface', 4624 4635 'DrydockSlotLock' => 'DrydockDAO', 4625 4636 'DrydockSlotLockException' => 'Exception', 4637 + 'DrydockSlotLockFailureLogType' => 'DrydockLogType', 4626 4638 'DrydockWebrootInterface' => 'DrydockInterface', 4627 4639 'DrydockWorker' => 'PhabricatorWorker', 4628 4640 'DrydockWorkingCopyBlueprintImplementation' => 'DrydockBlueprintImplementation',
+9 -7
src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
··· 172 172 // Destroy the lease on the host. 173 173 $lease->releaseOnDestruction(); 174 174 175 - // Destroy the working copy on disk. 176 - $command_type = DrydockCommandInterface::INTERFACE_TYPE; 177 - $interface = $lease->getInterface($command_type); 175 + if ($lease->isActive()) { 176 + // Destroy the working copy on disk. 177 + $command_type = DrydockCommandInterface::INTERFACE_TYPE; 178 + $interface = $lease->getInterface($command_type); 178 179 179 - $root_key = 'workingcopy.root'; 180 - $root = $resource->getAttribute($root_key); 181 - if (strlen($root)) { 182 - $interface->execx('rm -rf -- %s', $root); 180 + $root_key = 'workingcopy.root'; 181 + $root = $resource->getAttribute($root_key); 182 + if (strlen($root)) { 183 + $interface->execx('rm -rf -- %s', $root); 184 + } 183 185 } 184 186 } 185 187
+4
src/applications/drydock/exception/DrydockSlotLockException.php
··· 22 22 parent::__construct($message); 23 23 } 24 24 25 + public function getLockMap() { 26 + return $this->lockMap; 27 + } 28 + 25 29 }
+22
src/applications/drydock/logtype/DrydockLeaseActivationFailureLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseActivationFailureLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.activation-failure'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Activation Failed'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-times red'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + $class = idx($data, 'class'); 17 + $message = idx($data, 'message'); 18 + 19 + return pht('Lease activation failed: [%s] %s', $class, $message); 20 + } 21 + 22 + }
+23
src/applications/drydock/logtype/DrydockLeaseActivationYieldLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseActivationYieldLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.activation-yield'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Waiting for Activation'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-clock-o green'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + $duration = idx($data, 'duration'); 17 + 18 + return pht( 19 + 'Waiting %s second(s) for lease to activate.', 20 + new PhutilNumber($duration)); 21 + } 22 + 23 + }
+25
src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseWaitingForResourcesLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.waiting-for-resources'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Waiting For Resource'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-clock-o yellow'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + $viewer = $this->getViewer(); 17 + 18 + $blueprint_phids = idx($data, 'blueprintPHIDs', array()); 19 + 20 + return pht( 21 + 'Waiting for available resources from: %s.', 22 + $viewer->renderHandleList($blueprint_phids)); 23 + } 24 + 25 + }
+22
src/applications/drydock/logtype/DrydockResourceActivationFailureLogType.php
··· 1 + <?php 2 + 3 + final class DrydockResourceActivationFailureLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.resource.activation-failure'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Activation Failed'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-times red'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + $class = idx($data, 'class'); 17 + $message = idx($data, 'message'); 18 + 19 + return pht('Resource activation failed: [%s] %s', $class, $message); 20 + } 21 + 22 + }
+23
src/applications/drydock/logtype/DrydockResourceActivationYieldLogType.php
··· 1 + <?php 2 + 3 + final class DrydockResourceActivationYieldLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.resource.activation-yield'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Waiting for Activation'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-clock-o green'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + $duration = idx($data, 'duration'); 17 + 18 + return pht( 19 + 'Waiting %s second(s) for resource to activate.', 20 + new PhutilNumber($duration)); 21 + } 22 + 23 + }
+26
src/applications/drydock/logtype/DrydockSlotLockFailureLogType.php
··· 1 + <?php 2 + 3 + final class DrydockSlotLockFailureLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.resource.slot-lock.failure'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Slot Lock Failure'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-lock yellow'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + $locks = idx($data, 'locks', array()); 17 + if ($locks) { 18 + return pht( 19 + 'Failed to acquire slot locks: %s.', 20 + implode(', ', array_keys($locks))); 21 + } else { 22 + return pht('Failed to acquire slot locks.'); 23 + } 24 + } 25 + 26 + }
+16 -4
src/applications/drydock/storage/DrydockLease.php
··· 232 232 } 233 233 234 234 $this->openTransaction(); 235 + try { 236 + try { 237 + DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); 238 + $this->slotLocks = array(); 239 + } catch (DrydockSlotLockException $ex) { 240 + $this->logEvent( 241 + DrydockSlotLockFailureLogType::LOGCONST, 242 + array( 243 + 'locks' => $ex->getLockMap(), 244 + )); 245 + throw $ex; 246 + } 235 247 236 248 $this 237 249 ->setResourcePHID($resource->getPHID()) 238 250 ->attachResource($resource) 239 251 ->setStatus($new_status) 240 252 ->save(); 241 - 242 - DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); 243 - $this->slotLocks = array(); 244 - 253 + } catch (Exception $ex) { 254 + $this->killTransaction(); 255 + throw $ex; 256 + } 245 257 $this->saveTransaction(); 246 258 247 259 $this->isAcquired = true;
+31 -4
src/applications/drydock/storage/DrydockResource.php
··· 135 135 $new_status = DrydockResourceStatus::STATUS_PENDING; 136 136 } 137 137 138 + $phid = $this->generatePHID(); 139 + 138 140 $this->openTransaction(); 141 + try { 142 + try { 143 + DrydockSlotLock::acquireLocks($phid, $this->slotLocks); 144 + $this->slotLocks = array(); 145 + } catch (DrydockSlotLockException $ex) { 146 + $this->logEvent( 147 + DrydockSlotLockFailureLogType::LOGCONST, 148 + array( 149 + 'locks' => $ex->getLockMap(), 150 + )); 151 + throw $ex; 152 + } 139 153 140 154 $this 155 + ->setPHID($phid) 141 156 ->setStatus($new_status) 142 157 ->save(); 143 - 144 - DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); 145 - $this->slotLocks = array(); 146 - 158 + } catch (Exception $ex) { 159 + $this->killTransaction(); 160 + throw $ex; 161 + } 147 162 $this->saveTransaction(); 148 163 149 164 $this->isAllocated = true; ··· 255 270 default: 256 271 return true; 257 272 } 273 + } 274 + 275 + public function logEvent($type, array $data = array()) { 276 + $log = id(new DrydockLog()) 277 + ->setEpoch(PhabricatorTime::getNow()) 278 + ->setType($type) 279 + ->setData($data); 280 + 281 + $log->setResourcePHID($this->getPHID()); 282 + $log->setBlueprintPHID($this->getBlueprintPHID()); 283 + 284 + return $log->save(); 258 285 } 259 286 260 287