private function buildPropertyListView(DrydockResource $resource, PhabricatorActionListView $actions)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setActionList($actions);
     $status = $resource->getStatus();
     $status = DrydockResourceStatus::getNameForStatus($status);
     $view->addProperty(pht('Status'), $status);
     $until = $resource->getUntil();
     if ($until) {
         $until_display = phabricator_datetime($until, $viewer);
     } else {
         $until_display = phutil_tag('em', array(), pht('Never'));
     }
     $view->addProperty(pht('Expires'), $until_display);
     $view->addProperty(pht('Resource Type'), $resource->getType());
     $view->addProperty(pht('Blueprint'), $viewer->renderHandle($resource->getBlueprintPHID()));
     $attributes = $resource->getAttributes();
     if ($attributes) {
         $view->addSectionHeader(pht('Attributes'), 'fa-list-ul');
         foreach ($attributes as $key => $value) {
             $view->addProperty($key, $value);
         }
     }
     return $view;
 }
 private function activateResource(DrydockResource $resource)
 {
     $resource_status = $resource->getStatus();
     if ($resource_status != DrydockResourceStatus::STATUS_PENDING) {
         throw new PhabricatorWorkerPermanentFailureException(pht('Trying to activate resource from wrong status ("%s").', $resource_status));
     }
     $blueprint = $resource->getBlueprint();
     $blueprint->activateResource($resource);
     $this->validateActivatedResource($blueprint, $resource);
 }
 private function destroyResource(DrydockResource $resource)
 {
     $status = $resource->getStatus();
     switch ($status) {
         case DrydockResourceStatus::STATUS_RELEASED:
         case DrydockResourceStatus::STATUS_BROKEN:
             break;
         default:
             throw new PhabricatorWorkerPermanentFailureException(pht('Unable to destroy resource ("%s"), resource has the wrong ' . 'status ("%s").', $resource->getPHID(), $status));
     }
     $blueprint = $resource->getBlueprint();
     $blueprint->destroyResource($resource);
     $resource->setStatus(DrydockResourceStatus::STATUS_DESTROYED)->save();
 }
 private function buildPropertyListView(DrydockResource $resource, PhabricatorActionListView $actions)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setActionList($actions);
     $status = $resource->getStatus();
     $status = DrydockResourceStatus::getNameForStatus($status);
     $view->addProperty(pht('Status'), $status);
     $view->addProperty(pht('Resource Type'), $resource->getType());
     $view->addProperty(pht('Blueprint'), $viewer->renderHandle($resource->getBlueprintPHID()));
     $attributes = $resource->getAttributes();
     if ($attributes) {
         $view->addSectionHeader(pht('Attributes'), 'fa-list-ul');
         foreach ($attributes as $key => $value) {
             $view->addProperty($key, $value);
         }
     }
     return $view;
 }
 private function releaseResource(DrydockResource $resource)
 {
     if ($resource->getStatus() != DrydockResourceStatus::STATUS_ACTIVE) {
         // If we had multiple release commands
         // This command is only meaningful to resources in the "Open" state.
         return;
     }
     $viewer = $this->getViewer();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     $resource->openTransaction();
     $resource->setStatus(DrydockResourceStatus::STATUS_RELEASED)->save();
     // TODO: Hold slot locks until destruction?
     DrydockSlotLock::releaseLocks($resource->getPHID());
     $resource->saveTransaction();
     $statuses = array(DrydockLeaseStatus::STATUS_PENDING, DrydockLeaseStatus::STATUS_ACQUIRED, DrydockLeaseStatus::STATUS_ACTIVE);
     $leases = id(new DrydockLeaseQuery())->setViewer($viewer)->withResourcePHIDs(array($resource->getPHID()))->withStatuses($statuses)->execute();
     foreach ($leases as $lease) {
         $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
         $lease->scheduleUpdate();
     }
     PhabricatorWorker::scheduleTask('DrydockResourceDestroyWorker', array('resourcePHID' => $resource->getPHID()), array('objectPHID' => $resource->getPHID()));
 }
示例#6
0
 public function activateOnResource(DrydockResource $resource)
 {
     $expect_status = DrydockLeaseStatus::STATUS_ACQUIRED;
     $actual_status = $this->getStatus();
     if ($actual_status != $expect_status) {
         throw new Exception(pht('Trying to activate a lease which has the wrong status: status ' . 'must be "%s", actually "%s".', $expect_status, $actual_status));
     }
     if ($resource->getStatus() == DrydockResourceStatus::STATUS_PENDING) {
         // TODO: Be stricter about this?
         throw new Exception(pht('Trying to activate a lease on a pending resource.'));
     }
     $this->openTransaction();
     $this->setStatus(DrydockLeaseStatus::STATUS_ACTIVE)->save();
     DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);
     $this->slotLocks = array();
     $this->saveTransaction();
     $this->isActivated = true;
     $this->didActivate();
     return $this;
 }
 /**
  * @task break
  */
 private function breakResource(DrydockResource $resource, Exception $ex)
 {
     switch ($resource->getStatus()) {
         case DrydockResourceStatus::STATUS_BROKEN:
         case DrydockResourceStatus::STATUS_RELEASED:
         case DrydockResourceStatus::STATUS_DESTROYED:
             // If the resource was already broken, just throw a normal exception.
             // This will retry the task eventually.
             throw new PhutilProxyException(pht('Unexpected failure while destroying resource ("%s").', $resource->getPHID()), $ex);
     }
     $resource->setStatus(DrydockResourceStatus::STATUS_BROKEN)->save();
     $resource->scheduleUpdate();
     $resource->logEvent(DrydockResourceActivationFailureLogType::LOGCONST, array('class' => get_class($ex), 'message' => $ex->getMessage()));
     throw new PhabricatorWorkerPermanentFailureException(pht('Permanent failure while activating resource ("%s"): %s', $resource->getPHID(), $ex->getMessage()));
 }