Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-03 01:09:07 +01:00
|
|
|
final class DrydockPreallocatedHostBlueprintImplementation
|
|
|
|
extends DrydockBlueprintImplementation {
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
|
|
|
|
public function isEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-03 01:09:07 +01:00
|
|
|
public function getDescription() {
|
|
|
|
return pht('Leases out preallocated, remote hosts.');
|
|
|
|
}
|
|
|
|
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
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) {
|
|
|
|
|
2013-12-04 22:16:33 +01:00
|
|
|
// Because preallocated resources are manually created, we should verify
|
|
|
|
// we have all the information we need.
|
|
|
|
PhutilTypeSpec::checkMap(
|
|
|
|
$resource->getAttributesForTypeSpec(
|
2013-12-04 22:17:23 +01:00
|
|
|
array('platform', 'host', 'port', 'credential', 'path')),
|
2013-12-04 22:16:33 +01:00
|
|
|
array(
|
|
|
|
'platform' => 'string',
|
|
|
|
'host' => 'string',
|
|
|
|
'port' => 'string', // Value is a string from the command line
|
2013-12-04 22:17:23 +01:00
|
|
|
'credential' => 'string',
|
2013-12-04 22:16:33 +01:00
|
|
|
'path' => 'string',
|
|
|
|
));
|
|
|
|
$v_platform = $resource->getAttribute('platform');
|
|
|
|
$v_path = $resource->getAttribute('path');
|
|
|
|
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
// 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 = '/';
|
2013-12-04 22:16:33 +01:00
|
|
|
if ($v_platform === 'windows') {
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
$separator = '\\';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the directory path a little.
|
2013-12-04 22:16:33 +01:00
|
|
|
$base_path = rtrim($v_path, '/');
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
$base_path = rtrim($base_path, '\\');
|
|
|
|
$full_path = $base_path.$separator.$lease_id;
|
|
|
|
|
|
|
|
$cmd = $lease->getInterface('command');
|
|
|
|
|
2013-12-04 22:16:33 +01:00
|
|
|
if ($v_platform !== 'windows') {
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
$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'),
|
2013-12-04 22:17:23 +01:00
|
|
|
'credential' => $resource->getAttribute('credential'),
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
'platform' => $resource->getAttribute('platform')));
|
2013-12-06 04:11:05 +01:00
|
|
|
case 'filesystem':
|
|
|
|
return id(new DrydockSFTPFilesystemInterface())
|
|
|
|
->setConfiguration(array(
|
|
|
|
'host' => $resource->getAttribute('host'),
|
|
|
|
'port' => $resource->getAttribute('port'),
|
|
|
|
'credential' => $resource->getAttribute('credential')));
|
Drydock blueprint for preallocated remote hosts
Summary:
This adds a Drydock blueprint for preallocated, remote hosts. This will be used by the Harbormaster interface to allow users to specify remote hosts that builds can be run on.
This adds a `canAllocateResource` method to Drydock blueprints; it is used to detect whether a blueprint can allocate a resource for the given type and attributes.
Test Plan:
Ran:
```
bin/drydock lease --type host --attributes remote=true,preallocated=true,host=192.168.56.101,port=22,user=james,keyfile=,path=C:\\Build\\,platform=windows
```
and saw the "C:\Build\<id>" folder appear on the remote Windows machine. Viewed the lease and resource in Drydock as well.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley
CC: Korvin, epriestley, aran, jamesr
Maniphest Tasks: T4111
Differential Revision: https://secure.phabricator.com/D7593
2013-11-22 23:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception("No interface of type '{$type}'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|