@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+186 -25
+1
bin/drydock
··· 1 + ../scripts/drydock/drydock_control.php
+13 -25
scripts/drydock/drydock_control.php
··· 21 21 require_once $root.'/scripts/__init_script__.php'; 22 22 23 23 $args = new PhutilArgumentParser($argv); 24 - $args->parseStandardArguments(); 25 - $args->parse(array()); 26 - 27 - $allocator = new DrydockAllocator(); 28 - $allocator->setResourceType('webroot'); 29 - $lease = $allocator->allocate(); 30 - 31 - $lease->waitUntilActive(); 32 - 33 - 34 - $cmd = $lease->getInterface('webroot'); 35 - echo "URI: ".$cmd->getURI()."\n"; 36 - 37 - $lease->release(); 38 - 39 - die("Done.\n"); 40 - 41 - $i_file = $lease->getInterface('command'); 42 - 43 - list($stdout) = $i_file->execx('ls / ; echo -- ; uptime ; echo -- ; uname -n'); 44 - echo $stdout; 24 + $args->setTagline('manage drydock software resources'); 25 + $args->setSynopsis(<<<EOSYNOPSIS 26 + **drydock** __commmand__ [__options__] 27 + Manage Drydock stuff. NEW AND EXPERIMENTAL. 45 28 29 + EOSYNOPSIS 30 + ); 31 + $args->parseStandardArguments(); 46 32 47 - $lease->release(); 33 + $workflows = array( 34 + new DrydockManagementWaitForLeaseWorkflow(), 35 + new DrydockManagementLeaseWorkflow(), 36 + new PhutilHelpArgumentWorkflow(), 37 + ); 48 38 49 - 50 - // $i_http = $lease->getInterface('httpd'); 51 - // echo $i_http->getURI('/index.html')."\n"; 39 + $args->parseWorkflows($workflows);
+6
src/__phutil_library_map__.php
··· 430 430 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', 431 431 'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php', 432 432 'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php', 433 + 'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php', 434 + 'DrydockManagementWaitForLeaseWorkflow' => 'applications/drydock/management/DrydockManagementWaitForLeaseWorkflow.php', 435 + 'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php', 433 436 'DrydockPhabricatorApplicationBlueprint' => 'applications/drydock/blueprint/application/DrydockPhabricatorApplicationBlueprint.php', 434 437 'DrydockRemoteHostBlueprint' => 'applications/drydock/blueprint/DrydockRemoteHostBlueprint.php', 435 438 'DrydockResource' => 'applications/drydock/storage/DrydockResource.php', ··· 1659 1662 'DrydockLog' => 'DrydockDAO', 1660 1663 'DrydockLogController' => 'DrydockController', 1661 1664 'DrydockLogQuery' => 'PhabricatorOffsetPagedQuery', 1665 + 'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow', 1666 + 'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow', 1667 + 'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow', 1662 1668 'DrydockPhabricatorApplicationBlueprint' => 'DrydockBlueprint', 1663 1669 'DrydockRemoteHostBlueprint' => 'DrydockBlueprint', 1664 1670 'DrydockResource' => 'DrydockDAO',
+84
src/applications/drydock/management/DrydockManagementLeaseWorkflow.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class DrydockManagementLeaseWorkflow 20 + extends DrydockManagementWorkflow { 21 + 22 + public function didConstruct() { 23 + $this 24 + ->setName('lease') 25 + ->setSynopsis('Lease a resource.') 26 + ->setArguments( 27 + array( 28 + array( 29 + 'name' => 'type', 30 + 'param' => 'resource_type', 31 + 'help' => 'Resource type.', 32 + ), 33 + array( 34 + 'name' => 'spec', 35 + 'param' => 'name=value,...', 36 + 'help' => 'Resource specficiation.', 37 + ), 38 + )); 39 + } 40 + 41 + public function execute(PhutilArgumentParser $args) { 42 + $console = PhutilConsole::getConsole(); 43 + 44 + $resource_type = $args->getArg('type'); 45 + if (!$resource_type) { 46 + throw new PhutilArgumentUsageException( 47 + "Specify a resource type with `--type`."); 48 + } 49 + 50 + $spec = $args->getArg('spec'); 51 + if ($spec) { 52 + $options = new PhutilSimpleOptions(); 53 + $spec = $options->parse($spec); 54 + } 55 + 56 + $allocator = new DrydockAllocator(); 57 + $allocator->setResourceType($resource_type); 58 + if ($spec) { 59 + // TODO: Shove this in there. 60 + } 61 + 62 + $lease = $allocator->allocate(); 63 + 64 + $root = dirname(phutil_get_library_root('phabricator')); 65 + $wait = new ExecFuture( 66 + 'php -f %s wait-for-lease --id %s', 67 + $root.'/scripts/drydock/drydock_control.php', 68 + $lease->getID()); 69 + 70 + foreach (Futures(array($wait))->setUpdateInterval(1) as $key => $future) { 71 + if ($future) { 72 + $future->resolvex(); 73 + break; 74 + } 75 + 76 + // TODO: Pull logs. 77 + $console->writeErr("Working...\n"); 78 + } 79 + 80 + $console->writeOut("Acquired Lease %s\n", $lease->getID()); 81 + return 0; 82 + } 83 + 84 + }
+56
src/applications/drydock/management/DrydockManagementWaitForLeaseWorkflow.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class DrydockManagementWaitForLeaseWorkflow 20 + extends DrydockManagementWorkflow { 21 + 22 + public function didConstruct() { 23 + $this 24 + ->setName('wait-for-lease') 25 + ->setSynopsis('Wait for a lease to become available.') 26 + ->setArguments( 27 + array( 28 + array( 29 + 'name' => 'id', 30 + 'param' => 'lease_id', 31 + 'help' => 'Lease ID to wait for.', 32 + ), 33 + )); 34 + } 35 + 36 + public function execute(PhutilArgumentParser $args) { 37 + $lease_id = $args->getArg('id'); 38 + if (!$lease_id) { 39 + throw new PhutilArgumentUsageException( 40 + "Specify a lease ID with `--id`."); 41 + } 42 + 43 + $console = PhutilConsole::getConsole(); 44 + 45 + $lease = id(new DrydockLease())->load($lease_id); 46 + if (!$lease) { 47 + $console->writeErr("No such lease.\n"); 48 + return 1; 49 + } else { 50 + $lease->waitUntilActive(); 51 + $console->writeErr("Lease active.\n"); 52 + return 0; 53 + } 54 + } 55 + 56 + }
+26
src/applications/drydock/management/DrydockManagementWorkflow.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + abstract class DrydockManagementWorkflow 20 + extends PhutilArgumentWorkflow { 21 + 22 + public function isExecutable() { 23 + return true; 24 + } 25 + 26 + }