コード例 #1
0
 /**
  * @task activate
  */
 private function validateActivatedLease(DrydockBlueprint $blueprint, DrydockResource $resource, DrydockLease $lease)
 {
     if (!$lease->isActivatedLease()) {
         throw new Exception(pht('Blueprint "%s" (of type "%s") is not properly implemented: it ' . 'returned from "%s" without activating a lease.', $blueprint->getBlueprintName(), $blueprint->getClassName(), 'acquireLease()'));
     }
 }
コード例 #2
0
 /**
  * @task activate
  */
 private function validateActivatedResource(DrydockBlueprint $blueprint, DrydockResource $resource)
 {
     if (!$resource->isActivatedResource()) {
         throw new Exception(pht('Blueprint "%s" (of type "%s") is not properly implemented: %s ' . 'must actually allocate the resource it returns.', $blueprint->getBlueprintName(), $blueprint->getClassName(), 'allocateResource()'));
     }
 }
 private function loadServices(DrydockBlueprint $blueprint)
 {
     if (!$this->services) {
         $service_phids = $blueprint->getFieldValue('almanacServicePHIDs');
         if (!$service_phids) {
             throw new Exception(pht('This blueprint ("%s") does not define any Almanac Service PHIDs.', $blueprint->getBlueprintName()));
         }
         $viewer = PhabricatorUser::getOmnipotentUser();
         $services = id(new AlmanacServiceQuery())->setViewer($viewer)->withPHIDs($service_phids)->withServiceClasses($this->getAlmanacServiceClasses())->needBindings(true)->execute();
         $services = mpull($services, null, 'getPHID');
         if (count($services) != count($service_phids)) {
             $missing_phids = array_diff($service_phids, array_keys($services));
             throw new Exception(pht('Some of the Almanac Services defined by this blueprint ' . 'could not be loaded. They may be invalid, no longer exist, ' . 'or be of the wrong type: %s.', implode(', ', $missing_phids)));
         }
         $this->services = $services;
     }
     return $this->services;
 }
コード例 #4
0
 /**
  * Make sure that a lease was really acquired properly.
  *
  * @param DrydockBlueprint Blueprint which created the resource.
  * @param DrydockResource Resource which was acquired.
  * @param DrydockLease The lease which was supposedly acquired.
  * @return void
  * @task lease
  */
 private function validateAcquiredLease(DrydockBlueprint $blueprint, DrydockResource $resource, DrydockLease $lease)
 {
     if (!$lease->isAcquiredLease()) {
         throw new Exception(pht('Blueprint "%s" (of type "%s") is not properly implemented: it ' . 'returned from "%s" without acquiring a lease.', $blueprint->getBlueprintName(), $blueprint->getClassName(), 'acquireLease()'));
     }
     $lease_phid = $lease->getResourcePHID();
     $resource_phid = $resource->getPHID();
     if ($lease_phid !== $resource_phid) {
         // TODO: Destroy the lease?
         throw new Exception(pht('Blueprint "%s" (of type "%s") is not properly implemented: it ' . 'returned from "%s" with a lease acquired on the wrong resource.', $blueprint->getBlueprintName(), $blueprint->getClassName(), 'acquireLease()'));
     }
 }