1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-08 22:01:03 +01:00

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
This commit is contained in:
epriestley 2015-10-01 08:11:42 -07:00
parent 4ac82be5ed
commit 6b775e6090
11 changed files with 213 additions and 15 deletions

View file

@ -831,6 +831,8 @@ phutil_register_library_map(array(
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php', 'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php', 'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php',
'DrydockLeaseActivatedLogType' => 'applications/drydock/logtype/DrydockLeaseActivatedLogType.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', 'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php',
'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php', 'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php',
'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php', 'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php',
@ -845,6 +847,7 @@ phutil_register_library_map(array(
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php', 'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php', 'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php',
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php', 'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
'DrydockLeaseWaitingForResourcesLogType' => 'applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php',
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php', 'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php',
'DrydockLogGarbageCollector' => 'applications/drydock/garbagecollector/DrydockLogGarbageCollector.php', 'DrydockLogGarbageCollector' => 'applications/drydock/garbagecollector/DrydockLogGarbageCollector.php',
@ -862,6 +865,8 @@ phutil_register_library_map(array(
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php', 'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php',
'DrydockQuery' => 'applications/drydock/query/DrydockQuery.php', 'DrydockQuery' => 'applications/drydock/query/DrydockQuery.php',
'DrydockResource' => 'applications/drydock/storage/DrydockResource.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', 'DrydockResourceController' => 'applications/drydock/controller/DrydockResourceController.php',
'DrydockResourceDatasource' => 'applications/drydock/typeahead/DrydockResourceDatasource.php', 'DrydockResourceDatasource' => 'applications/drydock/typeahead/DrydockResourceDatasource.php',
'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php', 'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php',
@ -877,6 +882,7 @@ phutil_register_library_map(array(
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php', 'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
'DrydockSlotLock' => 'applications/drydock/storage/DrydockSlotLock.php', 'DrydockSlotLock' => 'applications/drydock/storage/DrydockSlotLock.php',
'DrydockSlotLockException' => 'applications/drydock/exception/DrydockSlotLockException.php', 'DrydockSlotLockException' => 'applications/drydock/exception/DrydockSlotLockException.php',
'DrydockSlotLockFailureLogType' => 'applications/drydock/logtype/DrydockSlotLockFailureLogType.php',
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php', 'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
'DrydockWorker' => 'applications/drydock/worker/DrydockWorker.php', 'DrydockWorker' => 'applications/drydock/worker/DrydockWorker.php',
'DrydockWorkingCopyBlueprintImplementation' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php', 'DrydockWorkingCopyBlueprintImplementation' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php',
@ -4571,6 +4577,8 @@ phutil_register_library_map(array(
), ),
'DrydockLeaseAcquiredLogType' => 'DrydockLogType', 'DrydockLeaseAcquiredLogType' => 'DrydockLogType',
'DrydockLeaseActivatedLogType' => 'DrydockLogType', 'DrydockLeaseActivatedLogType' => 'DrydockLogType',
'DrydockLeaseActivationFailureLogType' => 'DrydockLogType',
'DrydockLeaseActivationYieldLogType' => 'DrydockLogType',
'DrydockLeaseController' => 'DrydockController', 'DrydockLeaseController' => 'DrydockController',
'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource', 'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource',
'DrydockLeaseDestroyedLogType' => 'DrydockLogType', 'DrydockLeaseDestroyedLogType' => 'DrydockLogType',
@ -4585,6 +4593,7 @@ phutil_register_library_map(array(
'DrydockLeaseStatus' => 'DrydockConstants', 'DrydockLeaseStatus' => 'DrydockConstants',
'DrydockLeaseUpdateWorker' => 'DrydockWorker', 'DrydockLeaseUpdateWorker' => 'DrydockWorker',
'DrydockLeaseViewController' => 'DrydockLeaseController', 'DrydockLeaseViewController' => 'DrydockLeaseController',
'DrydockLeaseWaitingForResourcesLogType' => 'DrydockLogType',
'DrydockLog' => array( 'DrydockLog' => array(
'DrydockDAO', 'DrydockDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
@ -4608,6 +4617,8 @@ phutil_register_library_map(array(
'DrydockDAO', 'DrydockDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
), ),
'DrydockResourceActivationFailureLogType' => 'DrydockLogType',
'DrydockResourceActivationYieldLogType' => 'DrydockLogType',
'DrydockResourceController' => 'DrydockController', 'DrydockResourceController' => 'DrydockController',
'DrydockResourceDatasource' => 'PhabricatorTypeaheadDatasource', 'DrydockResourceDatasource' => 'PhabricatorTypeaheadDatasource',
'DrydockResourceListController' => 'DrydockResourceController', 'DrydockResourceListController' => 'DrydockResourceController',
@ -4623,6 +4634,7 @@ phutil_register_library_map(array(
'DrydockSSHCommandInterface' => 'DrydockCommandInterface', 'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
'DrydockSlotLock' => 'DrydockDAO', 'DrydockSlotLock' => 'DrydockDAO',
'DrydockSlotLockException' => 'Exception', 'DrydockSlotLockException' => 'Exception',
'DrydockSlotLockFailureLogType' => 'DrydockLogType',
'DrydockWebrootInterface' => 'DrydockInterface', 'DrydockWebrootInterface' => 'DrydockInterface',
'DrydockWorker' => 'PhabricatorWorker', 'DrydockWorker' => 'PhabricatorWorker',
'DrydockWorkingCopyBlueprintImplementation' => 'DrydockBlueprintImplementation', 'DrydockWorkingCopyBlueprintImplementation' => 'DrydockBlueprintImplementation',

View file

@ -172,14 +172,16 @@ final class DrydockWorkingCopyBlueprintImplementation
// Destroy the lease on the host. // Destroy the lease on the host.
$lease->releaseOnDestruction(); $lease->releaseOnDestruction();
// Destroy the working copy on disk. if ($lease->isActive()) {
$command_type = DrydockCommandInterface::INTERFACE_TYPE; // Destroy the working copy on disk.
$interface = $lease->getInterface($command_type); $command_type = DrydockCommandInterface::INTERFACE_TYPE;
$interface = $lease->getInterface($command_type);
$root_key = 'workingcopy.root'; $root_key = 'workingcopy.root';
$root = $resource->getAttribute($root_key); $root = $resource->getAttribute($root_key);
if (strlen($root)) { if (strlen($root)) {
$interface->execx('rm -rf -- %s', $root); $interface->execx('rm -rf -- %s', $root);
}
} }
} }

View file

@ -22,4 +22,8 @@ final class DrydockSlotLockException extends Exception {
parent::__construct($message); parent::__construct($message);
} }
public function getLockMap() {
return $this->lockMap;
}
} }

View file

@ -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);
}
}

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

@ -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));
}
}

View file

@ -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.');
}
}
}

View file

@ -232,16 +232,28 @@ final class DrydockLease extends DrydockDAO
} }
$this->openTransaction(); $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 $this
->setResourcePHID($resource->getPHID()) ->setResourcePHID($resource->getPHID())
->attachResource($resource) ->attachResource($resource)
->setStatus($new_status) ->setStatus($new_status)
->save(); ->save();
} catch (Exception $ex) {
DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); $this->killTransaction();
$this->slotLocks = array(); throw $ex;
}
$this->saveTransaction(); $this->saveTransaction();
$this->isAcquired = true; $this->isAcquired = true;

View file

@ -135,15 +135,30 @@ final class DrydockResource extends DrydockDAO
$new_status = DrydockResourceStatus::STATUS_PENDING; $new_status = DrydockResourceStatus::STATUS_PENDING;
} }
$phid = $this->generatePHID();
$this->openTransaction(); $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 $this
->setPHID($phid)
->setStatus($new_status) ->setStatus($new_status)
->save(); ->save();
} catch (Exception $ex) {
DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); $this->killTransaction();
$this->slotLocks = array(); throw $ex;
}
$this->saveTransaction(); $this->saveTransaction();
$this->isAllocated = true; $this->isAllocated = true;
@ -257,6 +272,18 @@ final class DrydockResource extends DrydockDAO
} }
} }
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 )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */