Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3281432
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
index 7260ba8999..03a381c3d6 100644
--- a/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
@@ -1,99 +1,114 @@
<?php
final class DrydockPreallocatedHostBlueprintImplementation
extends DrydockBlueprintImplementation {
public function isEnabled() {
return true;
}
public function getDescription() {
return pht('Leases out preallocated, remote hosts.');
}
public function canAllocateMoreResources(array $pool) {
return false;
}
protected function executeAllocateResource(DrydockLease $lease) {
throw new Exception("Preallocated hosts can't be dynamically allocated.");
}
protected function canAllocateLease(
DrydockResource $resource,
DrydockLease $lease) {
return
$lease->getAttribute('platform') === $resource->getAttribute('platform');
}
protected function shouldAllocateLease(
DrydockResource $resource,
DrydockLease $lease,
array $other_leases) {
return true;
}
protected function executeAcquireLease(
DrydockResource $resource,
DrydockLease $lease) {
+ // Because preallocated resources are manually created, we should verify
+ // we have all the information we need.
+ PhutilTypeSpec::checkMap(
+ $resource->getAttributesForTypeSpec(
+ array('platform', 'host', 'port', 'user', 'path')),
+ array(
+ 'platform' => 'string',
+ 'host' => 'string',
+ 'port' => 'string', // Value is a string from the command line
+ 'user' => 'string',
+ 'path' => 'string',
+ ));
+ $v_platform = $resource->getAttribute('platform');
+ $v_path = $resource->getAttribute('path');
+
// Similar to DrydockLocalHostBlueprint, we create a folder
// on the remote host that the lease can use.
$lease_id = $lease->getID();
// Can't use DIRECTORY_SEPERATOR here because that is relevant to
// the platform we're currently running on, not the platform we are
// remoting to.
$separator = '/';
- if ($lease->getAttribute('platform') === 'windows') {
+ if ($v_platform === 'windows') {
$separator = '\\';
}
// Clean up the directory path a little.
- $base_path = rtrim($resource->getAttribute('path'), '/');
+ $base_path = rtrim($v_path, '/');
$base_path = rtrim($base_path, '\\');
$full_path = $base_path.$separator.$lease_id;
$cmd = $lease->getInterface('command');
- if ($lease->getAttribute('platform') !== 'windows') {
+ if ($v_platform !== 'windows') {
$cmd->execx('mkdir %s', $full_path);
} else {
// Windows is terrible. The mkdir command doesn't even support putting
// the path in quotes. IN QUOTES. ARGUHRGHUGHHGG!! Do some terribly
// inaccurate sanity checking since we can't safely escape the path.
if (preg_match('/^[A-Z]\\:\\\\[a-zA-Z0-9\\\\\\ ]/', $full_path) === 0) {
throw new Exception(
'Unsafe path detected for Windows platform: "'.$full_path.'".');
}
$cmd->execx('mkdir %C', $full_path);
}
$lease->setAttribute('path', $full_path);
}
public function getType() {
return 'host';
}
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'),
'user' => $resource->getAttribute('user'),
'ssh-keyfile' => $resource->getAttribute('ssh-keyfile'),
'platform' => $resource->getAttribute('platform')));
}
throw new Exception("No interface of type '{$type}'.");
}
}
diff --git a/src/applications/drydock/storage/DrydockResource.php b/src/applications/drydock/storage/DrydockResource.php
index 4e847883c1..87e7f7dc9a 100644
--- a/src/applications/drydock/storage/DrydockResource.php
+++ b/src/applications/drydock/storage/DrydockResource.php
@@ -1,114 +1,118 @@
<?php
final class DrydockResource extends DrydockDAO
implements PhabricatorPolicyInterface {
protected $id;
protected $phid;
protected $blueprintPHID;
protected $status;
protected $type;
protected $name;
protected $attributes = array();
protected $capabilities = array();
protected $ownerPHID;
private $blueprint;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'attributes' => self::SERIALIZATION_JSON,
'capabilities' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_DRYR);
}
public function getAttribute($key, $default = null) {
return idx($this->attributes, $key, $default);
}
+ public function getAttributesForTypeSpec(array $attribute_names) {
+ return array_select_keys($this->attributes, $attribute_names);
+ }
+
public function setAttribute($key, $value) {
$this->attributes[$key] = $value;
return $this;
}
public function getCapability($key, $default = null) {
return idx($this->capbilities, $key, $default);
}
public function getInterface(DrydockLease $lease, $type) {
return $this->getBlueprint()->getInterface($this, $lease, $type);
}
public function getBlueprint() {
if (empty($this->blueprint)) {
$blueprint = id(new DrydockBlueprint())
->loadOneWhere('phid = %s', $this->blueprintPHID);
$this->blueprint = $blueprint->getImplementation();
}
return $this->blueprint;
}
public function closeResource() {
$this->openTransaction();
$leases = id(new DrydockLease())->loadAllWhere(
'resourceID = %d AND status IN (%Ld)',
$this->getID(),
array(
DrydockLeaseStatus::STATUS_PENDING,
DrydockLeaseStatus::STATUS_ACTIVE,
));
foreach ($leases as $lease) {
switch ($lease->getStatus()) {
case DrydockLeaseStatus::STATUS_PENDING:
$message = pht('Breaking pending lease (resource closing).');
$lease->setStatus(DrydockLeaseStatus::STATUS_BROKEN);
break;
case DrydockLeaseStatus::STATUS_ACTIVE:
$message = pht('Releasing active lease (resource closing).');
$lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED);
break;
}
DrydockBlueprintImplementation::writeLog($this, $lease, $message);
$lease->save();
}
$this->setStatus(DrydockResourceStatus::STATUS_CLOSED);
$this->save();
$this->saveTransaction();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
public function describeAutomaticCapability($capability) {
return null;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Mar 23, 22:21 (1 w, 44 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1114163
Default Alt Text
(7 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment