private function processCommand(DrydockLease $lease, DrydockCommand $command)
 {
     switch ($command->getCommand()) {
         case DrydockCommand::COMMAND_RELEASE:
             $this->releaseLease($lease);
             break;
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $ids = $args->getArg('id');
     if (!$ids) {
         throw new PhutilArgumentUsageException(pht('Specify one or more lease IDs to release with "%s".', '--id'));
     }
     $viewer = $this->getViewer();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     $leases = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs($ids)->execute();
     PhabricatorWorker::setRunAllTasksInProcess(true);
     foreach ($ids as $id) {
         $lease = idx($leases, $id);
         if (!$lease) {
             echo tsprintf("%s\n", pht('Lease "%s" does not exist.', $id));
             continue;
         }
         if (!$lease->canRelease()) {
             echo tsprintf("%s\n", pht('Lease "%s" is not releasable.', $id));
             continue;
         }
         $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
         $lease->scheduleUpdate();
         echo tsprintf("%s\n", pht('Scheduled release of lease "%s".', $id));
     }
 }
 public function releaseArtifact(PhabricatorUser $actor)
 {
     $lease = $this->loadArtifactLease($actor);
     if (!$lease->canRelease()) {
         return;
     }
     $command = DrydockCommand::initializeNewCommand($actor)->setTargetPHID($lease->getPHID())->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
     $lease->scheduleUpdate();
 }
Пример #4
0
 public function __destruct()
 {
     if (!$this->releaseOnDestruction) {
         return;
     }
     if (!$this->canRelease()) {
         return;
     }
     $actor = PhabricatorUser::getOmnipotentUser();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     $command = DrydockCommand::initializeNewCommand($actor)->setTargetPHID($this->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
     $this->scheduleUpdate();
 }
 public function releaseArtifact(PhabricatorUser $actor)
 {
     $lease = $this->loadArtifactLease($actor);
     if (!$lease->canRelease()) {
         return;
     }
     $author_phid = $actor->getPHID();
     if (!$author_phid) {
         $author_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
     }
     $command = DrydockCommand::initializeNewCommand($actor)->setTargetPHID($lease->getPHID())->setAuthorPHID($author_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
     $lease->scheduleUpdate();
 }
Пример #6
0
 private function checkObjectExpiration($object)
 {
     // Check if the resource or lease has expired. If it has, we're going to
     // send it a release command.
     // This command is sent from within the update worker so it is handled
     // immediately, but doing this generates a log and improves consistency.
     $expires = $object->getUntil();
     if (!$expires) {
         return;
     }
     $now = PhabricatorTime::getNow();
     if ($expires > $now) {
         return;
     }
     $viewer = $this->getViewer();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($object->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
 }
 public function releaseArtifact(PhabricatorUser $actor)
 {
     try {
         $lease = $this->loadArtifactLease($actor);
     } catch (Exception $ex) {
         // If we can't load the lease, treat it as already released. Artifacts
         // are generated before leases are queued, so it's possible to arrive
         // here under normal conditions.
         return;
     }
     if (!$lease->canRelease()) {
         return;
     }
     $author_phid = $actor->getPHID();
     if (!$author_phid) {
         $author_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
     }
     $command = DrydockCommand::initializeNewCommand($actor)->setTargetPHID($lease->getPHID())->setAuthorPHID($author_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
     $lease->scheduleUpdate();
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $resource = id(new DrydockResourceQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$resource) {
         return new Aphront404Response();
     }
     $resource_uri = '/resource/' . $resource->getID() . '/';
     $resource_uri = $this->getApplicationURI($resource_uri);
     if (!$resource->canRelease()) {
         return $this->newDialog()->setTitle(pht('Resource Not Releasable'))->appendParagraph(pht('Resources can not be released after they are destroyed.'))->addCancelButton($resource_uri);
     }
     if ($request->isFormPost()) {
         $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($resource->getPHID())->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
         $resource->scheduleUpdate();
         return id(new AphrontRedirectResponse())->setURI($resource_uri);
     }
     return $this->newDialog()->setTitle(pht('Really release resource?'))->appendChild(pht('Releasing a resource releases all leases and destroys the ' . 'resource. It can not be undone.'))->addSubmitButton(pht('Release Resource'))->addCancelButton($resource_uri);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $lease = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$lease) {
         return new Aphront404Response();
     }
     $lease_uri = '/lease/' . $lease->getID() . '/';
     $lease_uri = $this->getApplicationURI($lease_uri);
     if (!$lease->canRelease()) {
         return $this->newDialog()->setTitle(pht('Lease Not Releasable'))->appendParagraph(pht('Leases can not be released after they are destroyed.'))->addCancelButton($lease_uri);
     }
     if ($request->isFormPost()) {
         $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
         $lease->scheduleUpdate();
         return id(new AphrontRedirectResponse())->setURI($lease_uri);
     }
     return $this->newDialog()->setTitle(pht('Release Lease?'))->appendParagraph(pht('Forcefully releasing a lease may interfere with the operation ' . 'of the lease holder and trigger destruction of the underlying ' . 'resource. It can not be undone.'))->addSubmitButton(pht('Release Lease'))->addCancelButton($lease_uri);
 }
 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()));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $viewer = $this->getViewer();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     PhabricatorWorker::setRunAllTasksInProcess(true);
     $resources = id(new DrydockResourceQuery())->setViewer($viewer)->withStatuses(array(DrydockResourceStatus::STATUS_ACTIVE))->execute();
     foreach ($resources as $resource) {
         $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($resource->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RECLAIM)->save();
         $resource->scheduleUpdate();
         $resource = $resource->reload();
         $name = pht('Resource %d: %s', $resource->getID(), $resource->getResourceName());
         switch ($resource->getStatus()) {
             case DrydockResourceStatus::STATUS_RELEASED:
             case DrydockResourceStatus::STATUS_DESTROYED:
                 echo tsprintf("%s\n", pht('Resource "%s" was reclaimed.', $name));
                 break;
             default:
                 echo tsprintf("%s\n", pht('Resource "%s" could not be reclaimed.', $name));
                 break;
         }
     }
 }
 /**
  * @task release
  */
 private function releaseResource(DrydockResource $resource)
 {
     $viewer = $this->getViewer();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     $resource->setStatus(DrydockResourceStatus::STATUS_RELEASED)->save();
     $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();
     }
     $this->destroyResource($resource);
 }
Пример #13
0
 protected function reclaimResource(DrydockResource $resource, DrydockLease $lease)
 {
     $viewer = $this->getViewer();
     $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($resource->getPHID())->setAuthorPHID($lease->getPHID())->setCommand(DrydockCommand::COMMAND_RECLAIM)->save();
     $resource->scheduleUpdate();
     return $this;
 }