1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Allow Drydock to allocate (very basic) working copy resources

Summary: This is missing a lot of features, but technically allows working copy allocation.

Test Plan: Ran `drydock lease --type working-copy --attributes repositoryID=12`, got a working copy of Phabricator allocated on disk.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D3999
This commit is contained in:
epriestley 2012-11-27 12:48:14 -08:00
parent 5cbc31644b
commit b04114f95c
5 changed files with 91 additions and 4 deletions

View file

@ -444,6 +444,7 @@ phutil_register_library_map(array(
'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php',
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
'DrydockWorkingCopyBlueprint' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprint.php',
'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php',
'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php',
'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php',
@ -1701,6 +1702,7 @@ phutil_register_library_map(array(
'DrydockResourceViewController' => 'DrydockController',
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
'DrydockWebrootInterface' => 'DrydockInterface',
'DrydockWorkingCopyBlueprint' => 'DrydockBlueprint',
'FeedPublisherWorker' => 'PhabricatorWorker',
'HarbormasterDAO' => 'PhabricatorLiskDAO',
'HarbormasterObject' => 'HarbormasterDAO',

View file

@ -36,6 +36,10 @@ abstract class DrydockBlueprint {
$this->log('Acquiring Lease');
try {
$lease->setStatus(DrydockLeaseStatus::STATUS_ACTIVE);
$lease->setResourceID($resource->getID());
$lease->attachResource($resource);
$this->executeAcquireLease($resource, $lease);
} catch (Exception $ex) {
$this->logException($ex);
@ -45,8 +49,6 @@ abstract class DrydockBlueprint {
throw $ex;
}
$lease->setResourceID($resource->getID());
$lease->setStatus(DrydockLeaseStatus::STATUS_ACTIVE);
$lease->save();
$this->activeResource = null;

View file

@ -30,6 +30,7 @@ final class DrydockLocalHostBlueprint extends DrydockBlueprint {
$resource = $this->newResourceTemplate('localhost');
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
$resource->setAttribute('path', $path);
$resource->save();
return $resource;
@ -38,6 +39,15 @@ final class DrydockLocalHostBlueprint extends DrydockBlueprint {
protected function executeAcquireLease(
DrydockResource $resource,
DrydockLease $lease) {
$lease_id = $lease->getID();
$cmd = $lease->getInterface('command');
$cmd->execx('mkdir %s', $lease_id);
$lease->setAttribute('path', $resource->getAttribute('path').'/'.$lease_id);
$lease->save();
return;
}

View file

@ -0,0 +1,69 @@
<?php
final class DrydockWorkingCopyBlueprint extends DrydockBlueprint {
public function isEnabled() {
return PhabricatorEnv::getEnvConfig('drydock.localhost.enabled');
}
protected function executeAllocateResource(DrydockLease $lease) {
$repository_id = $lease->getAttribute('repositoryID');
if (!$repository_id) {
throw new Exception(
"Lease is missing required 'repositoryID' attribute.");
}
$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!");
}
$host_lease = id(new DrydockLease())
->setResourceType('host')
->waitUntilActive();
$path = $host_lease->getAttribute('path').'/'.$repository->getCallsign();
$cmd = $host_lease->getInterface('command');
$cmd->execx(
'git clone --origin origin %s %s',
$repository->getRemoteURI(),
$path);
$resource = $this->newResourceTemplate($repository->getCallsign());
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
$resource->setAttribute('lease.host', $host_lease->getID());
$resource->setAttribute('path', $path);
$resource->save();
return $resource;
}
protected function executeAcquireLease(
DrydockResource $resource,
DrydockLease $lease) {
return;
}
public function getType() {
return 'working-copy';
}
public function getInterface(
DrydockResource $resource,
DrydockLease $lease,
$type) {
throw new Exception("No interface of type '{$type}'.");
}
}

View file

@ -26,12 +26,12 @@ final class DrydockLease extends DrydockDAO {
}
public function setAttribute($key, $value) {
$this->attributes[$key] = $value;
$this->attributes[strtolower($key)] = $value;
return $this;
}
public function getAttribute($key, $default = null) {
return idx($this->attributes, $key, $default);
return idx($this->attributes, strtolower($key), $default);
}
public function generatePHID() {
@ -150,6 +150,10 @@ final class DrydockLease extends DrydockDAO {
}
public function waitUntilActive() {
if (!$this->getID()) {
$this->queueForActivation();
}
self::waitForLeases(array($this));
return $this;
}