protected function executeAllocateResource(DrydockLease $lease) { $repository_id = $lease->getAttribute('repositoryID'); if (!$repository_id) { throw new Exception("Lease is missing required 'repositoryID' attribute."); } // TODO: (T603) Figure out the interaction between policies and // Drydock. $repository = id(new PhabricatorRepository())->load($repository_id); if (!$repository) { throw new Exception("Repository '{$repository_id}' does not exist!"); } switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: break; default: throw new Exception('Unsupported VCS!'); } // TODO: Policy stuff here too. $host_lease = id(new DrydockLease())->setResourceType('host')->waitUntilActive(); $path = $host_lease->getAttribute('path') . $repository->getCallsign(); $this->log(pht('Cloning %s into %s....', $repository->getCallsign(), $path)); $cmd = $host_lease->getInterface('command'); $cmd->execx('git clone --origin origin %P %s', $repository->getRemoteURIEnvelope(), $path); $this->log(pht('Complete.')); $resource = $this->newResourceTemplate('Working Copy (' . $repository->getCallsign() . ')'); $resource->setStatus(DrydockResourceStatus::STATUS_OPEN); $resource->setAttribute('lease.host', $host_lease->getID()); $resource->setAttribute('path', $path); $resource->setAttribute('repositoryID', $repository->getID()); $resource->save(); return $resource; }
public function activateLease(DrydockBlueprint $blueprint, DrydockResource $resource, DrydockLease $lease) { $command_type = DrydockCommandInterface::INTERFACE_TYPE; $interface = $lease->getInterface($command_type); $cmd = array(); $arg = array(); $cmd[] = 'git clean -d --force'; $cmd[] = 'git reset --hard HEAD'; $cmd[] = 'git fetch'; $commit = $lease->getAttribute('commit'); $branch = $lease->getAttribute('branch'); if ($commit !== null) { $cmd[] = 'git reset --hard %s'; $arg[] = $commit; } else { if ($branch !== null) { $cmd[] = 'git reset --hard %s'; $arg[] = $branch; } } $cmd = implode(' && ', $cmd); $argv = array_merge(array($cmd), $arg); $result = call_user_func_array(array($interface, 'execx'), $argv); $lease->activateOnResource($resource); }
public function getInterface(DrydockResource $resource, DrydockLease $lease, $type) { switch ($type) { case 'command': return id(new DrydockSSHCommandInterface())->setConfiguration(array('host' => $resource->getAttribute('host'), 'port' => $resource->getAttribute('port'), 'credential' => $resource->getAttribute('credential'), 'platform' => $resource->getAttribute('platform')))->setWorkingDirectory($lease->getAttribute('path')); case 'filesystem': return id(new DrydockSFTPFilesystemInterface())->setConfiguration(array('host' => $resource->getAttribute('host'), 'port' => $resource->getAttribute('port'), 'credential' => $resource->getAttribute('credential'))); } throw new Exception(pht("No interface of type '%s'.", $type)); }
public function getInterface(DrydockResource $resource, DrydockLease $lease, $type) { switch ($type) { case 'webroot': $iface = new DrydockApacheWebrootInterface(); $iface->setConfiguration(array('uri' => $lease->getAttribute('uri'))); return $iface; case 'command': $host_lease_id = $resource->getAttribute('lease.host'); $host_lease = id(new DrydockLease())->load($host_lease_id); $host_lease->attachResource($host_lease->loadResource()); return $host_lease->getInterface($type); } throw new Exception("No interface of type '{$type}'."); }
public function getInterface(DrydockBlueprint $blueprint, DrydockResource $resource, DrydockLease $lease, $type) { switch ($type) { case DrydockCommandInterface::INTERFACE_TYPE: $host_lease = $this->loadHostLease($resource); $command_interface = $host_lease->getInterface($type); $path = $lease->getAttribute('workingcopy.default'); $command_interface->setWorkingDirectory($path); return $command_interface; } }
public function getCommandError(DrydockLease $lease) { $error = $lease->getAttribute('workingcopy.vcs.error'); if (!$error) { return null; } else { return $error; } }
public function getCommandError(DrydockLease $lease) { return $lease->getAttribute('workingcopy.vcs.error'); }