[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/drydock/blueprint/ -> DrydockWorkingCopyBlueprintImplementation.php (source)

   1  <?php
   2  
   3  final class DrydockWorkingCopyBlueprintImplementation
   4    extends DrydockBlueprintImplementation {
   5  
   6    public function isEnabled() {
   7      return true;
   8    }
   9  
  10    public function getBlueprintName() {
  11      return pht('Working Copy');
  12    }
  13  
  14    public function getDescription() {
  15      return pht('Allows Drydock to check out working copies of repositories.');
  16    }
  17  
  18    protected function canAllocateLease(
  19      DrydockResource $resource,
  20      DrydockLease $lease) {
  21  
  22      $resource_repo = $resource->getAttribute('repositoryID');
  23      $lease_repo = $lease->getAttribute('repositoryID');
  24  
  25      return ($resource_repo && $lease_repo && ($resource_repo == $lease_repo));
  26    }
  27  
  28    protected function shouldAllocateLease(
  29      DrydockResource $resource,
  30      DrydockLease $lease,
  31      array $other_leases) {
  32  
  33      return !$other_leases;
  34    }
  35  
  36    protected function executeAllocateResource(DrydockLease $lease) {
  37      $repository_id = $lease->getAttribute('repositoryID');
  38      if (!$repository_id) {
  39        throw new Exception(
  40          "Lease is missing required 'repositoryID' attribute.");
  41      }
  42  
  43      // TODO: (T603) Figure out the interaction between policies and
  44      // Drydock.
  45      $repository = id(new PhabricatorRepository())->load($repository_id);
  46  
  47      if (!$repository) {
  48        throw new Exception(
  49          "Repository '{$repository_id}' does not exist!");
  50      }
  51  
  52      switch ($repository->getVersionControlSystem()) {
  53        case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
  54          break;
  55        default:
  56          throw new Exception('Unsupported VCS!');
  57      }
  58  
  59      // TODO: Policy stuff here too.
  60      $host_lease = id(new DrydockLease())
  61        ->setResourceType('host')
  62        ->waitUntilActive();
  63  
  64      $path = $host_lease->getAttribute('path').$repository->getCallsign();
  65  
  66      $this->log(
  67        pht('Cloning %s into %s....', $repository->getCallsign(), $path));
  68  
  69      $cmd = $host_lease->getInterface('command');
  70      $cmd->execx(
  71        'git clone --origin origin %P %s',
  72        $repository->getRemoteURIEnvelope(),
  73        $path);
  74  
  75      $this->log(pht('Complete.'));
  76  
  77      $resource = $this->newResourceTemplate(
  78        'Working Copy ('.$repository->getCallsign().')');
  79      $resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
  80      $resource->setAttribute('lease.host', $host_lease->getID());
  81      $resource->setAttribute('path', $path);
  82      $resource->setAttribute('repositoryID', $repository->getID());
  83      $resource->save();
  84  
  85      return $resource;
  86    }
  87  
  88    protected function executeAcquireLease(
  89      DrydockResource $resource,
  90      DrydockLease $lease) {
  91      return;
  92    }
  93  
  94    public function getType() {
  95      return 'working-copy';
  96    }
  97  
  98    public function getInterface(
  99      DrydockResource $resource,
 100      DrydockLease $lease,
 101      $type) {
 102  
 103      switch ($type) {
 104        case 'command':
 105          return $this
 106            ->loadLease($resource->getAttribute('lease.host'))
 107            ->getInterface($type);
 108      }
 109  
 110      throw new Exception("No interface of type '{$type}'.");
 111    }
 112  
 113  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1