1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-21 22:32:41 +01:00

Modernize the drydock script

Summary: Add a bin/drydock symlink and break it into workflows. Nothing too special here.

Test Plan: Ran `bin/drydock wait-for-lease`, `bin/drydock lease`, `bin/drydock help`, etc.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D3867
This commit is contained in:
epriestley 2012-11-01 15:30:14 -07:00
parent afae26ad94
commit 07dc943215
6 changed files with 186 additions and 25 deletions

1
bin/drydock Symbolic link
View file

@ -0,0 +1 @@
../scripts/drydock/drydock_control.php

View file

@ -21,31 +21,19 @@ $root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline('manage drydock software resources');
$args->setSynopsis(<<<EOSYNOPSIS
**drydock** __commmand__ [__options__]
Manage Drydock stuff. NEW AND EXPERIMENTAL.
EOSYNOPSIS
);
$args->parseStandardArguments();
$args->parse(array());
$allocator = new DrydockAllocator();
$allocator->setResourceType('webroot');
$lease = $allocator->allocate();
$workflows = array(
new DrydockManagementWaitForLeaseWorkflow(),
new DrydockManagementLeaseWorkflow(),
new PhutilHelpArgumentWorkflow(),
);
$lease->waitUntilActive();
$cmd = $lease->getInterface('webroot');
echo "URI: ".$cmd->getURI()."\n";
$lease->release();
die("Done.\n");
$i_file = $lease->getInterface('command');
list($stdout) = $i_file->execx('ls / ; echo -- ; uptime ; echo -- ; uname -n');
echo $stdout;
$lease->release();
// $i_http = $lease->getInterface('httpd');
// echo $i_http->getURI('/index.html')."\n";
$args->parseWorkflows($workflows);

View file

@ -430,6 +430,9 @@ phutil_register_library_map(array(
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php',
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
'DrydockManagementWaitForLeaseWorkflow' => 'applications/drydock/management/DrydockManagementWaitForLeaseWorkflow.php',
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php',
'DrydockPhabricatorApplicationBlueprint' => 'applications/drydock/blueprint/application/DrydockPhabricatorApplicationBlueprint.php',
'DrydockRemoteHostBlueprint' => 'applications/drydock/blueprint/DrydockRemoteHostBlueprint.php',
'DrydockResource' => 'applications/drydock/storage/DrydockResource.php',
@ -1659,6 +1662,9 @@ phutil_register_library_map(array(
'DrydockLog' => 'DrydockDAO',
'DrydockLogController' => 'DrydockController',
'DrydockLogQuery' => 'PhabricatorOffsetPagedQuery',
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow',
'DrydockPhabricatorApplicationBlueprint' => 'DrydockBlueprint',
'DrydockRemoteHostBlueprint' => 'DrydockBlueprint',
'DrydockResource' => 'DrydockDAO',

View file

@ -0,0 +1,84 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DrydockManagementLeaseWorkflow
extends DrydockManagementWorkflow {
public function didConstruct() {
$this
->setName('lease')
->setSynopsis('Lease a resource.')
->setArguments(
array(
array(
'name' => 'type',
'param' => 'resource_type',
'help' => 'Resource type.',
),
array(
'name' => 'spec',
'param' => 'name=value,...',
'help' => 'Resource specficiation.',
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$resource_type = $args->getArg('type');
if (!$resource_type) {
throw new PhutilArgumentUsageException(
"Specify a resource type with `--type`.");
}
$spec = $args->getArg('spec');
if ($spec) {
$options = new PhutilSimpleOptions();
$spec = $options->parse($spec);
}
$allocator = new DrydockAllocator();
$allocator->setResourceType($resource_type);
if ($spec) {
// TODO: Shove this in there.
}
$lease = $allocator->allocate();
$root = dirname(phutil_get_library_root('phabricator'));
$wait = new ExecFuture(
'php -f %s wait-for-lease --id %s',
$root.'/scripts/drydock/drydock_control.php',
$lease->getID());
foreach (Futures(array($wait))->setUpdateInterval(1) as $key => $future) {
if ($future) {
$future->resolvex();
break;
}
// TODO: Pull logs.
$console->writeErr("Working...\n");
}
$console->writeOut("Acquired Lease %s\n", $lease->getID());
return 0;
}
}

View file

@ -0,0 +1,56 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DrydockManagementWaitForLeaseWorkflow
extends DrydockManagementWorkflow {
public function didConstruct() {
$this
->setName('wait-for-lease')
->setSynopsis('Wait for a lease to become available.')
->setArguments(
array(
array(
'name' => 'id',
'param' => 'lease_id',
'help' => 'Lease ID to wait for.',
),
));
}
public function execute(PhutilArgumentParser $args) {
$lease_id = $args->getArg('id');
if (!$lease_id) {
throw new PhutilArgumentUsageException(
"Specify a lease ID with `--id`.");
}
$console = PhutilConsole::getConsole();
$lease = id(new DrydockLease())->load($lease_id);
if (!$lease) {
$console->writeErr("No such lease.\n");
return 1;
} else {
$lease->waitUntilActive();
$console->writeErr("Lease active.\n");
return 0;
}
}
}

View file

@ -0,0 +1,26 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class DrydockManagementWorkflow
extends PhutilArgumentWorkflow {
public function isExecutable() {
return true;
}
}